私はこのテキストファイルparams.txt
を次の名前で持っています:
3
WENSY WENDY
PING PING
CHLOE CHLOE
私の質問は、この入力を読み取って 2 つの文字列を 1 行で比較するにはどうすればよいですか? Wendy と Wendy などを比較してください。
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);
}
});
}
}
入力テキストを文字列変数に保存できますか? または、これを行う別の簡単な方法はありますか?ありがとうございました :))