Reputation: 11
It will print the array in the console so I know the loop is working but PrintWriter wont print anything in the file.
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();
}
}
Upvotes: 1
Views: 144
Reputation: 5936
use flush()
pr.flush();
or create autoflush PrintWriter
PrintWriter pw = new PrintWriter(..., true);
Upvotes: 1