public static void outputFile() {
HabitItem it;
try {
File path = new File("output.txt");
FileOutputStream fout = new FileOutputStream(path);
DataOutputStream dos = new DataOutputStream(fout);
while (!stackHabitItems.isEmpty()) {
it = stackHabitItems.pop();
dos.writeChars("<\n");
for(int i = 0; i < 7; i++) {
if (it.isDayCompleted[i]) {
dos.writeInt(1);
}
else {
dos.writeInt(0);
}
}
dos.writeChars("\n");
dos.writeInt(it.id);
dos.writeChars("\\>\n");
}
fout.close();
}
catch (Exception e) {
System.out.println("Failed to open file output.txt");
}
}
All I'm trying to do is write an array of booleans and an integer into a file enclosed by < />
My file might look like this (assuming one iteration) < 1 0 1 0 0 0 1 42 >
But the dos.writeInt is failing to produce normal output. Instead it displays
<
>
Where the blank spaces are filled by Squares
Why does my code not work? I feel like I'm using DataOutputStream correctly.