readtext.java
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:2k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package server;
- import java.io.EOFException;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.util.HashMap;
- public class readtext {
- public static ObjectInputStream ois;
- public static ObjectOutputStream oos;
- public static HashMap read(){
- HashMap set= new HashMap();
- try {
- ois =new ObjectInputStream(new FileInputStream("c:\user_info.txt"));
- qq_user user;
- while((user=(qq_user)ois.readObject())!=null){
- set.put(user.name, user);
- }
- ois.close();
- }catch(EOFException ea){
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return set;
- }
- public static void write(HashMap set){
- try {
- oos=new ObjectOutputStream(new FileOutputStream("c:\user_info.txt"));
- Object[] arr=set.keySet().toArray();
- for(int j=0;j<arr.length;j++){
- oos.writeObject((qq_user)set.get(arr[j]));
- System.out.println("woshishui");
- }
- oos.close();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }