i got trouble in reading/writing my game state into file
this is all about reading/writing STRING object into file
first, can i add String into the end of file?
(without have to rewrite all from the beginning)
i use FileWriter, BufferedWriter, and PrintWriter to do file writing.
like this :
private void fileWrite(String[] data,File fileName) {
try {
FileWriter out = new FileWriter(fileName);
BufferedWriter writeOut = new BufferedWriter(out);
PrintWriter fos = new PrintWriter(writeOut);
fos.println(data.length);
for (int i=0;i < data.length;i++)
fos.println(data[i]);
fos.close();
} catch (IOException e) { e.printStackTrace(); }
}
the String[] data is not append to the end of file, but make a new file.
second, how to read n line of file.
example i want to read line 27 of my file to line 36
and replace that lines, then write it to the same file again.
thanxx anyone