【发布时间】:2026-01-04 17:20:04
【问题描述】:
我正在使用此代码。
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 个不同的变量中吗?或者您只想将最后两行保存在 temp1 和 temp2 中?
-
想要将文件的前两行保存在两个不同的变量中。
标签: java android file-handling