【问题标题】:printwriter object not printing outprintwriter 对象没有打印出来
【发布时间】:2014-07-17 23:03:24
【问题描述】:

我的 PrintWriter 对象编写器的 print() 方法不起作用,我导入了所有适当的类,但 CSV 文件总是空白。谁能告诉我为什么?

public class StateStats {
    static String pathto = "....";

    public static void main(String[] args) throws FileNotFoundException, IOException {
       ReadFile st = new ReadFile(pathto+"stateAbbrev.csv");
       ReadFile abPop = new ReadFile(pathto+"AbbrevPop.csv");      
       ReadFile Perc = new ReadFile(pathto+"PopPercentAlpha.dat");


       PrintWriter writer = new PrintWriter(pathto+"StateAbbPop.csv","UTF-8");

       //this is the header for our new CSV file
       writer.write("State, Abbrev, Population, %of US");
       writer.write("\n");
    }
}

【问题讨论】:

    标签: java javascript methods printwriter


    【解决方案1】:

    您似乎忘记在 writer 上调用 flushclose。没有它,一些临时存储在缓冲区中的字符将不会发送到文件中。

    【讨论】:

    • 天哪,就是这样!它对我来说总是最简单的事情!谢谢!
    猜你喜欢
    • 2020-05-18
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多