它将在控制台中打印数组,因此我知道循环正在工作,但 PrintWriter 不会打印文件中的任何内容。
public static void writePuzzle(char[][] puzzle, String file){
try{
PrintWriter pr = new PrintWriter(new FileWriter ((file)));
for(int i= 0 ; i<puzzle.length; i++ ){
for(int j= 0 ; j<puzzle.length; j++ ){
pr.print(puzzle[i][j]);
System.out.print(puzzle[i][j]);
}
pr.println();
System.out.println("");
}
} catch (IOException e) {
e.printStackTrace();
}
}
最佳答案
包括:
pr.flush();
就在循环之后。
关于java - PrintWriter 在我的循环中不起作用,但我的循环正在工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26290811/