1、对于字节流读写基本数据类型,除了DataOutputstream 和DataIntputStream外,ObjectOutputStream、ObjectInputStream是读取对象数据,有个例子:
public static void saveObjects(ArrayList listData, String fileName) {
FileOutputStream os = new FileOutputStream("fileName.dat");
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(listData);
}
public static ArrayList readObjects(String fileName) {
ArrayList listDat;
Object obj;
try{
FileInputStream is = new FileInputStream("fileName.dat");
ObjectInputStream ois = new ObjectInputStream(is);
obj = ois.readObject();
}catch (Exception e) {
e.printStackTrace();
}
if(obj instanceof ArrayList){
listDat = (ArrayList)obj;
return listData;
}
return null;
}
2、对于字符流读取基本数据类型
CharArrayReader 可以从字符数组中读取数据 |