java - 当我打印数组时,它只显示 txt 文件的最后一行而不是整个内容?
问题描述
这是我从 txt 文件中读取的代码,然后将其内容添加到索引为 10 的数组中,我希望它列出所有内容,但它只列出最后一个 10 次。
String filePath10 = "src//SalmonSortingEfficiencies//10nums.txt";
String filePath10000 = "src//SalmonSortingEfficiencies//10000nums.txt";
String start;
boolean eof;
if (rBtn10.isSelected()) {
try {
String temp;
String phrase;
FileReader fr = new FileReader(filePath10);
//opens the stream to the text file
BufferedReader br = new BufferedReader(fr);
//Reads the data in the text file
eof = false;
while (!eof) {
start = br.readLine();
if (start == null) {
eof = true;
// sets eof to true if the name is null/seeing
// where the end of the file is so br stops reading
} else {
temp = br.readLine();
int smallArrayNumbers = Integer.parseInt(temp);
phrase = smallArrayNumbers + "\n";
for (int i = 0; i < 10; i++) {
smallArray[i] = phrase;
}
}
}
br.close();
} catch (IOException e) {
System.out.println("Error" + e);
//looks and prints out any errors found
}
for (String item : smallArray) {
txtONumbers.append(item);
}
}
解决方案
推荐阅读
- vba - 如何在 VBA 中激活用户窗体选项按钮(不为其分配值)
- node.js - 无法安装 node-sass
- django - django rest 框架 set_cookie 不工作
- flutter - 使用函数声明将函数绑定到名称
- sql - 带有自引用表的sql server递归查询
- docker - Docker compose:运行几个仅在命令上有所不同的容器
- amazon-web-services - Redshift 中上个月的最后一天
- amazon-web-services - 是否可以更新 Lambda 堆栈以更改 Lambda 的日志组?
- forms - google api 聊天机器人:如何从表单输入中读取值
- header - 如何在 SULU 的所有页面中创建树枝模板标题?