我的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");
}
}
答案 0 :(得分:2)
您似乎忘了在作家身上调用flush
或close
。没有它,一些临时存储在缓冲区中的字符将不会被发送到文件。