I have a method to write a file but somehow it is having problems writing an int
:
public static void writeFile(int[] result) {
try {
FileWriter writer = new FileWriter("MyFileExample.txt", true);
BufferedWriter bufferedWriter = new BufferedWriter(writer);
int counter = 0;
for (int j = 0; j < result.length; j++) {
if (result[j] != -1) {
counter++;
}
}
System.out.println(counter);
bufferedWriter.write(counter);
bufferedWriter.newLine();
for(int i = 0; i<result.length; i++) {
if (result[i] != -1) {
bufferedWriter.write(i + " ");
}
}
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
The line bufferedWriter.write(counter);
is not writing anything. Just a blank. The rest is getting written perfectly fine. I tried writing "test"
instead of counter
and that is perfectly fine as well.
Any idea on how to fix this issue?