Skip to content

Instantly share code, notes, and snippets.

@ckdevrel
Created August 2, 2015 20:10
Show Gist options
  • Save ckdevrel/0407136643dcd23f9991 to your computer and use it in GitHub Desktop.
Save ckdevrel/0407136643dcd23f9991 to your computer and use it in GitHub Desktop.
To Write a ArrayList<File>:
public static void createCachedFile (Context context, String key, ArrayList<File> fileName) throws IOException {
String tempFile = null;
for (File file : fileName) {
FileOutputStream fos = context.openFileOutput (key, Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream (fos);
oos.writeObject (fileName);
oos.close ();
fos.close ();
}
}
To Read a ArrayList<File>
public static Object readCachedFile (Context context, String key) throws IOException, ClassNotFoundException {
FileInputStream fis = context.openFileInput (key);
ObjectInputStream ois = new ObjectInputStream (fis);
Object object = ois.readObject ();
return object;
}
Final code in my Activity
createCachedFile (MainActivity.this,"apk",adapter.getAppList ());
ArrayList<File> apkCacheList = (ArrayList<File>)readCachedFile (MainActivity.this, "apk");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment