所以我尝试从文件中读取多行,然后将它们放入 String[] 中。但它似乎不起作用。我做错了什么?
String[] liniiFisier=new String[20];
int i=0;
try{
FileInputStream fstream = new FileInputStream("textfile.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
liniiFisier[i]=strLine;
i++;
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
for(int j=0;j<i;j++)
System.out.println(liniiFisier[i]);
最佳答案
将最后一行更改为
System.out.println(liniiFisier[j]); // important: use j, not i
关于java - 从文件读取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6395337/