I wrote a code to save my ArrayList to a file, but I need to read this file again, reuse the same array later, but the file is being writen in a weird way, is there any way I can configure the way that the output file will be writen? Sorry if the question is stupid, this is my first program.
Code to save the ArrayList:
try {
FileOutputStream fileOut = new FileOutputStream(
"src//ServerInfo.txt");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(dataServer);
out.close();
fileOut.close();
}
catch (IOException i) {
i.printStackTrace();
}
Code to read the file:
try {
File file = new File("src//ServerInfo.txt");
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
try {
String s;
while ((s = br.readLine()) != null) {
dataServer.add(s);
}
}
finally {
br.close();
}
}
catch (IOException ex) {
ex.printStackTrace();
}
Either changing the read or write code is okay, I just need a way to read the file I write.
Output file llok like this:
¬í sr java.util.ArrayListxÒ™Ça I sizexp w t admint admint booklet@booklet.comt
Administratorx
How it's supposed to look like: (it's also how I wrote it the first time, before the program did it)
admin
admin
booklet@booklet.com
Administrator