Java 如何保存ArrayList<;文件>;到Android中的文件?

Java 如何保存ArrayList<;文件>;到Android中的文件?,java,android,Java,Android,我正在开发一个android应用程序,它使用一个文件类型的ArrayList。 我想把它保存到一个文件中,然后再把它读回来。任何帮助都将不胜感激 ArrayList和File都实现了可序列化 所以要写入文件 FileOutputStream f = new FileOutputStream(new File("myFiles.txt")); ObjectOutputStream o = new ObjectOutputStream(f); o.writeObject(m

我正在开发一个android应用程序,它使用一个文件类型的ArrayList。
我想把它保存到一个文件中,然后再把它读回来。任何帮助都将不胜感激

ArrayList和File都实现了可序列化

所以要写入文件

FileOutputStream f = new FileOutputStream(new File("myFiles.txt"));             
ObjectOutputStream o = new ObjectOutputStream(f);
o.writeObject(myArrayListOfFiles);
o.close();
f.close(); 
然后从文件中读取

FileInputStream fi = new FileInputStream(new File("myFiles.txt"));          
ObjectInputStream oi = new ObjectInputStream(fi);
ArrayList<File> myArrayListOfFiles = (ArrayList<File>) oi.readObject();     
oi.close();
fi.close();
然后把它读回来

byte[] data = Base64.decode(myString, Base64.DEFAULT);
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
ArrayList<File> o = (ArrayList<File>) ois.readObject();
ois.close();
byte[]data=Base64.decode(myString,Base64.DEFAULT);
ObjectInputStream ois=新的ObjectInputStream(新的ByteArrayInputStream(数据));
ArrayList o=(ArrayList)ois.readObject();
ois.close();

保存文件路径,而不是保存
文件
对象如果我的答案是您想要的,您应该将其标记为已接受,以便人们知道您的帖子不需要进一步关注
byte[] data = Base64.decode(myString, Base64.DEFAULT);
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
ArrayList<File> o = (ArrayList<File>) ois.readObject();
ois.close();