【发布时间】:2015-09-08 16:43:44
【问题描述】:
我正在创建一个项目,我需要在其中读取从 .java 文件中的关键字开始的特定行。
我将不得不阅读 .java 文件:
Intent myIntent = new Intent(StudentMap.this, StudentPref.class);
StudentMap.this.startActivity(myIntent);
我将如何在代码中的任何位置阅读这两行。我应该为此设置正则表达式,但是如何设置?
我正在使用:
public void onClick(View v) {
TextView responseText = (TextView) findViewById(R.id.responseText);
String myData = "";
String test = "Intent ";
// String name="";
switch (v.getId()) {
case R.id.getExternalStorage:
try {
FileInputStream fis = new FileInputStream(myExternalFile);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null){
myData = myData + strLine;
if (strLine.equals(test)) {
tv1.setText(tv1.getText() + strLine + "\n");
}
else{
tv1.setText(tv1.getText() + "nakaam" + "\n");
}
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
responseText.setText("MySampleFile.java data retrieved from external Storage...");
break;
}
tv1.setText(tv1.getText() + myData + "\n"+"\n"+"\n"+"end");
//tv1.setText(tv1.getText() + strLine + "\n");
}
据我所知,Intent 关键字在每个文件中都是静态的,因此我可以获得像“Intent”这样的行首,但是如何仅从大文件中读取这一行和下一行..?
【问题讨论】: