我试图在遵循预设参考的线上抓取一条数据
这是我到目前为止的代码,它只是抓住了文本中的所有内容
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.btnRead) {
try {
readfile();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Problems: " + e.getMessage(), 1).show();
}
}
private void readfile() throws IOException {
String str="";
StringBuffer buf = new StringBuffer();
InputStream is = this.getResources().openRawResource(R.drawable.test);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is!=null) {
while ((str = reader.readLine()) != null) {
buf.append(str + "\n" );
}
}
is.close();
Toast.makeText(getBaseContext(), buf.toString(), Toast.LENGTH_LONG).show();
我考虑过添加这样的东西
if (str == "name:"){
reader.readNextLine();
}
else {
(buf.append("Referance not found" + "\n"));
}
这样它会找到预设的单词并立即抓住下一行显然我做不到
readNextLine
所以试图找到另一种简单的方法