[Q] How to save a Map, which has non-primitive data, in a file
From: maya2000 (sungwoo.lim_at_brunel.ac.uk)
Date: 01/30/04
- Next message: Paukstadt: "Free Submission"
- Previous message: baby pink: "Re: Solve the problem....its urgent"
- Next in thread: hiwa: "Re: [Q] How to save a Map, which has non-primitive data, in a file"
- Reply: hiwa: "Re: [Q] How to save a Map, which has non-primitive data, in a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Jan 2004 03:22:43 -0800
Hello,
Below code has a problem to read a data. It seems the non-primitive
data are the reason. How can I save this Map into a file, and read it
later?
Thanks in advance.
//-------------------------------------------------------------------------
import java.io.*;
import java.util.*;
public class StoreData implements Serializable {
public Map siMap = new HashMap();
public Map newMap = null;
public StoreData(int strokeNumber, Vector Vector1, Array array2) {
siMap.put("_strokeNumber", new Integer(strokeNumber));
siMap.put("_Vector1", Vector1);
siMap.put("_Array2", Array2);
}
public void saveData(String filename) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(filename);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(siMap);
oos.flush();
fos.close();
} catch(IOException e) {
e.printStackTrace();
}
}
public void loadData(String filename) {
FileInputStream fis = null;
try {
fis = new FileInputStream(filename);
ObjectInputStream ois = new ObjectInputStream(fis);
newMap = (Map)ois.readObject();
fis.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
//-------------------------------------------------------------------------
- Next message: Paukstadt: "Free Submission"
- Previous message: baby pink: "Re: Solve the problem....its urgent"
- Next in thread: hiwa: "Re: [Q] How to save a Map, which has non-primitive data, in a file"
- Reply: hiwa: "Re: [Q] How to save a Map, which has non-primitive data, in a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|