我有这个名为的文本文件params.txt
,其中包括:
3
WENSY WENDY
PING PING
CHLOE CHLOE
我的问题是,如何读取这些输入并在一行中比较两个字符串?比较 Wensy 和 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);
}
});
}
}
我可以将输入文本保存在字符串变量上吗?或者还有另一种简单的方法可以做到这一点?谢谢你 :))