mercredi 6 mai 2015

Android serialization issue

I am trying to write object data to a file (how it's done in a standard java program) in an android program and am running in to some issues. Here's the code:

public static final String storeDir = "Adata"; 
public static final String storeFile = "albums";


public static void write(ArrayList<Album> albums) throws IOException {
    ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(storeDir + File.separator + storeFile));
    oos.writeObject(albums);
}

public static ArrayList<Album> read() throws IOException, ClassNotFoundException{
    ObjectInputStream ois = new ObjectInputStream( new FileInputStream(storeDir + File.separator + storeFile));

    return (ArrayList<Album>)ois.readObject();
}

At startup the app crashes and says, "java.io.FileNotFoundException: Adata/albums (No such file or directory)

The folder Adata folder is in the project folder at the same point as the src. Any help is appreciated. Thanks.

Aucun commentaire:

Enregistrer un commentaire