gpt4 book ai didi

java - 从文本文件加载后为空白

转载 作者:行者123 更新时间:2023-11-30 04:13:53 26 4
gpt4 key购买 nike

我正在尝试从文本文件输出有关电视节目的信息,如下所示:

2
PPL
Tuesday
1900
BBT
Thursday
2100

我读取和输出文件的方法如下所示:

//method to read shows from file
public static void loadFile() throws FileNotFoundException, IOException{
int i;
int x = 0;
BufferedReader input = new BufferedReader(new FileReader("TV.txt"));
x = Integer.valueOf(input.readLine()).intValue();
System.out.println(x + " shows!");

for(i = 0; i < show.size(); i++){
((showInfo)show.get(i)).name = input.readLine();
((showInfo)show.get(i)).day = input.readLine();
((showInfo)show.get(i)).time = Integer.valueOf(input.readLine()).intValue();
}

System.out.println("Show Information");
for(i = 0; i < show.size(); i++){
System.out.println("Name: " + ((showInfo)show.get(i)).name);
System.out.println("Day: " + ((showInfo)show.get(i)).day);
System.out.println("Time: " + ((showInfo)show.get(i)).time);
}
}

它向我显示了节目数量和“节目信息”,但随后它是空白的并返回到主菜单。它为什么要这样做?哦,请不要问我为什么使用强制转换而不是泛型。我不能,因为我必须使用 1.4。我的老师希望如此。

任何帮助都会很棒!提前致谢。 :)

最佳答案

我假设show是一些Collection类型。

我最好的猜测是,在调用此函数之前,show实际上还没有任何东西(即 show.size() 为 0)。

x是节目的数量,你可能应该像for (int i = 0; i < x; i++)这样循环,并创建 showInfo 的新实例使用您的数据,并将其插入 show在你的循环中。

关于java - 从文本文件加载后为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18905920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com