1 回答
TA贡献1744条经验 获得超4个赞
我不明白“应该存储在字符串中”是什么意思。如果您需要以“h”开头的行,只需创建一个ArrayList字符串并将其保存在那里。
// Declare an ArrayList first
private ArrayList<String> lineStore = new ArrayList<String>();
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1000 && resultCode == RESULT_OK) {
String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
try {
BufferedReader br = new BufferedReader(new FileReader(filePath));
String line;
while ((line = br.readLine()) != null) {
if (line.startsWith("h")) {
// Store the line in the ArrayList to be used later
lineStore.add(line); // That's what you meant?
}
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
添加回答
举报