Java程序未打印到末尾。

huangapple go评论67阅读模式
英文:

Java program is not printing to the end

问题

我有一个关于我的简单应用程序的问题。它从CSV文件中打印一些文本到TXT文件,它运行得很好,但不是一直运行到最后,它在大约90%处停止并结束。无论CSV文件中有多少行,它都会在模型的一半左右停止。

我尝试增加和减少行数,尝试在控制台中打印模型,它可以正常工作,我正在使用FileWriter。

英文:

Hi I have an issue with my simple app. It is printing from csv file some text to the txt file it is working well, but not to the end, It stops at like 90% and ends. It doesn't matter how many rows are in the csv file it stops like in half of model and ends

I was increasing and decrasing number of rows, tried to print models in console and it worked, i am using Filewrtitter

答案1

得分: 2

可能的原因之一是您在使用后未关闭FileWriter。
而不是这种结构:

var fileWriter = new FileWriter("filename.txt");
// 在这里使用fileWriter

尝试像这样做:

try (var fileWriter = new FileWriter("filename.txt")) {
    // 在这里使用fileWriter
}

然后,try-with-resources语句将自动关闭您的写入器。

英文:

One possible reason is that you are not closing your FileWriter after use.
Instead of this structure:

    var fileWriter = new FileWriter("filename.txt");
    // use fileWriter here

Try doing it like this:

    try (var fileWriter = new FileWriter("filename.txt")) {
        // use fileWriter here
    }

The try-with-resources statement will then automatically close your writer.

huangapple
  • 本文由 发表于 2023年7月13日 19:52:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定