I've spent all day on this and need some advice!
I'm trying to save the contents of a Array List into a text file.
I have got android to save the array list contents to an internal *.txt however after entering "Test one" and "Test Two" into the array list, and a button is clicked to save the current contents into the text file. I get the following:
�� sr java.util.ArrayListx����a� I sizexp w t Test Onet Test Twox
An Error is also given which is:
"File was loaded in the wrong encoding:'UTF-8'
The System.out.print
gives the results:
"I/System.out: [Test One, Test Two]"
which is accurate to show the contents of the array list.
Code used:
public void savingfile() {
read = (Button)findViewById(R.id.read);
read.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
outputStream = openFileOutput(anxfile, Context.MODE_PRIVATE);
ObjectOutputStream out = new ObjectOutputStream(outputStream);
out.writeObject(arrayList);
System.out.println(arrayList);
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
Many thanks, Leon P.S. I have tried many youtube tutorials/Stackoverflow answers to fix the problem but still having the same issue