-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidFileSystem.txt
More file actions
29 lines (27 loc) · 1.18 KB
/
Copy pathAndroidFileSystem.txt
File metadata and controls
29 lines (27 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public static void save(ArrayList<Element> elements, File file, Context context){
try {
ObjectOutputStream obos = new ObjectOutputStream(context.openFileOutput(file.getName(),Context.MODE_PRIVATE));
obos.writeObject(elements);
obos.close();
}catch (IOException io){
Log.e("Exception", "File write failed: " + io.toString());
}
}
public static ArrayList<Element> remember(File file, Context context){
ArrayList<Element> elements = new ArrayList<>();
try{
InputStream inputStream = context.openFileInput(file.getName());
if (inputStream != null){
ObjectInputStream obis = new ObjectInputStream(inputStream);
elements = (ArrayList<Element>) obis.readObject();
obis.close();
}else {
MainActivity.toaster(context,"inputStream == null");
}
}catch (IOException io){
Log.e("Exception", "Can not read file: " + io.toString());
}catch (ClassNotFoundException cnfe){
Log.e("Exception", "Class not found: " + cnfe.toString());
}
return elements;
}