Created
August 2, 2015 20:10
-
-
Save ckdevrel/0407136643dcd23f9991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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