javacsvtxtexport-to-text

Java program is not printing to the end


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


Solution

  • 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.