我使用此代碼。如何在android中逐行閱讀?
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("config.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
while ((br.readLine()) != null) {
temp1 = br.readLine();
temp2 = br.readLine();
}
in.close();
}catch (Exception e){//Catch exception if any
Toast.makeText(getBaseContext(), "Exception", Toast.LENGTH_LONG).show();
}
Toast.makeText(getBaseContext(), temp1+temp2, Toast.LENGTH_LONG).show();
但這是顯示異常並且不更新temp1和temp2。
你想存儲在2級不同的變量在同一行?或者你只是想將最後2行保存在temp1和temp2中? – SERPRO
想要在兩個不同的變量中保存前兩行文件。 – xkrlaix