Я этот текстовый файл с именем params.txt
, которые состоят из:Чтение входного текстового файла и сравнения (Android)
3
WENSY WENDY
PING PING
CHLOE CHLOE
Мой вопрос, как я могу прочитать эти входы и сравнить две строки в одной строке? Сравните Wensy и Венди и так далее ..
Code:
public class MainActivity extends Activity {
InputStream is=null;
DataInputStream dis=null;
Resources myResources = null;
TextView tv=null;
String someText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button verify = (Button) findViewById (R.id.verify);
myResources = this.getResources();
tv = (TextView)findViewById(R.id.FileViewer);
is = myResources.openRawResource(R.raw.params);
dis = new DataInputStream(is);
someText = null;
verify.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
someText=dis.readLine();
}catch(IOException ioe){
someText ="Couldn't read the file";
}
tv.setText(someText);
}
});
}
}
Могу ли я сохранить введенный текст на переменную String? Или есть еще один простой способ сделать это? thankyou :))
Что вы попробовали? – newuser
Добавлен код @newuser. Я не знаю, как сравнить две строки. – pingboo23