jeudi 12 mars 2015

Android - Writing object to file



I have a method that's supposed to write an object to a file and I've tried a variety of methods but I either don't write to the file or I go into my catch statement, my code is as:



public void createFoo(Foo foo)
{
ObjectOutputStream out = null;
try
{
out = new ObjectOutputStream(new FileOutputStream("C:\\Users\\PERSON\\AndroidStudioProjects\\PROJECT\\bar.dat"));
out.writeObject(event);
Log.i("CreateFoo", "Write success");
}
catch (IOException e)
{
Log.i("CreateFoo", "Write - Catch error can't find .dat");
}
finally
{
try
{
out.close();
}
catch (Exception e)
{
Log.i("CreateFoo", "Write - Failed to close object output stream.");
}
}
}


I've tried looking at other threads but I'm still having trouble, my Foo object also has implements Serializable in its declaration.




Aucun commentaire:

Enregistrer un commentaire