将输出数据写入文本文件会导致文本文件中的结果不完整 [英] Writing output data to text file gives incomplete result in text file

查看:80
本文介绍了将输出数据写入文本文件会导致文本文件中的结果不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有14个列表,每个列表都有数字或字符串数​​据。每个列表的大小为32561。我必须输出以下格式的文件:

I have 14 lists and each list have either numeric or string data. Size of each list is 32561. I have to output a file with the format:

list1_element1   list2_element1.......................list14_element1
list1_element2   list2_element2.......................list14_element2
.
.
.
.
.
list1_element32561   list2_element32561.......................list14_element32561

输出文件中的每个元素都由制表符空间分隔。

Each element in output file is separated by tab space. I did it like this in Java.

        out = new BufferedWriter(new FileWriter(fileName));
        for(int i=0; i<32561; i++) {
        out.write(firstList.get(i));
        out.write("\t");
        out.write(secondList.get(i));
        out.write("\t");
        out.write(thirdList.get(i));
        out.write("\t");
        out.write(fourthList.get(i));
        out.write("\t");
        out.write(fifthList.get(i));
        out.write("\t");
        out.write(sixthList.get(i));
        out.write("\t");
        out.write(seventhList.get(i));
        out.write("\t");
        out.write(eighthList.get(i));
        out.write("\t");
        out.write(ninthList.get(i));
        out.write("\t");
        out.write(tenthList.get(i));
        out.write("\t");
        out.write(eleventhList.get(i));
        out.write("\t");
        out.write(twelvethList.get(i));
        out.write("\t");
        out.write(thirteenthList.get(i));
        out.write("\t");
        out.write(fourteenthList.get(i));
            out.write("\t");
        out.write(fifteenthList.get(i));

        out.newLine();
    }
}

我的程序仅打印32441行,最后一行包括仅6列。我不明白为什么。有人可以帮忙吗?

My program prints only 32441 lines with the last line consisting of only 6 columns. I don't understand why. Can someone help ?

推荐答案

您没有关闭 Writer ,因此您将丢失缓冲区中仍存的任何内容。

You aren't closing the Writer, so you're losing whatever is still in the buffer.

这篇关于将输出数据写入文本文件会导致文本文件中的结果不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆