android完全支持ObjectOutputStream
比如我在这个帖子里的示例代码:byte[] bytes = null;
OutputStream out = null;
...
ObjectOutputStream objOutput = new ObjectOutputStream(out);
objOutput.writeShort((short)bytes.length);

解决方案 »

  1.   

    可以讲我存在文件夹里的List<User>对象集合给读出来么?
      

  2.   

    当然可以。class User {
    private String name;
    private int age;
    public void writeToOutputStream(ObjectOutputStream output) throws IOException {
    output.writeUTF(name);
    output.writeInt(age);
    }
    public void readFromInputStream(ObjectInputStream input) throws IOException {
    name = input.readUTF();
    age = input.readInt();
    }
    }
      

  3.   


    public static void writeUserListToOutputStream(List<User> users, ObjectOutputStream output) throws IOException {
    output.writeInt(users.size());
    for (User user : users) {
    user.writeToOutputStream(output);
    }
    }
    public static List<User> readUserListFromInputStream(ObjectInputStream input) throws IOException {
    List<User> users = new LinkedList<User>();
    int count = input.readInt();
    for (int i = 0; i < count; i++) {
    User user = new User();
    user.readFromInputStream(input);
    users.add(user);
    }
    return users;
    }
      

  4.   

    谢谢解答了,我自己最后忍不了了,用了SAX解析XML了,准备把文件变成XML再读取