0
我有一个数组列表,这是我创建的类的类型。我已经使用objectoutputstream将该数组列表写入文件。现在我已经把它作为一个对象读回来了,但是我怎么把它重新放回我的数组列表中?对象自定义类Arraylist
//Open external storage
File root = android.os.Environment.getExternalStorageDirectory();
//Get directory path
File dir = new File(root.getAbsolutePath() + "/download");
File file = new File(dir, "userAccounts.txt");
try{
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
UserAccounts tempUser = (UserAccounts) ois.readObject();
Global.getInstance().userArray.add(tempUser);
ois.close();
Toast.makeText(getApplicationContext(), Global.getInstance().userArray.get(0).aUsername, Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
类
package com.example.cg4project;
import java.io.Serializable;
public class UserAccounts implements Serializable{
/**
*
*/
public int aID;
public String aUsername;
public String aFirstName;
public String aLastName;
public String aemail;
v
如果我的ArrayList是一个全球性的ArrayList如何将我去有关存储它在那 – xiimoss
我更新了我的答案,以显示如何将结果放入您的全局数组 – brwngrldev
非常感谢! – xiimoss