Okay so I’ve got my class ( sorry about the formatting, not too familiar with the site )
import java.io.*;
public class writingArray
{
public static void writeToFile(String fileName, String[] input) {
PrintWriter printWriter;
try {
printWriter = new PrintWriter(new FileOutputStream(fileName, true));
int length = input.length;
int i;
for(i = 0; ++i < length; i++) {
printWriter.println(input[i]);
}
printWriter.close();
}
catch(IOException e) {
System.out.println(e.getMessage());
}
}
}
The problem is I want to write an array to a file with each entry being on a separate line and I want to wipe the file at the start from each write. Any advice on what to do? Because all I’ve managed to do is write the last entry of the array while wiping all the previous entries and yet I can write the last entry several times below itself.
Thanks ^^
I don’t think you want to increase i twice. Get rid of the ++i.