Java 有注册/登录程序,但可以';无法保存多个配置文件

Java 有注册/登录程序,但可以';无法保存多个配置文件,java,serialization,deserialization,Java,Serialization,Deserialization,我用Java攻击了我自己的prgeam,但我不能让程序保存一个以上的prgeam文件,因为它会给我一条未知源的错误消息 序列化注册配置文件的代码 int br1 = 4, br = 0; ArrayList<Object> dObjects = new ArrayList<Object>(); try { FileInputStream FileIn = new FileInputStrea

我用Java攻击了我自己的prgeam,但我不能让程序保存一个以上的prgeam文件,因为它会给我一条未知源的错误消息

序列化注册配置文件的代码

int br1 = 4, br = 0;
            ArrayList<Object> dObjects = new ArrayList<Object>();
            try {

                FileInputStream FileIn = new FileInputStream("users.ser");
                ObjectInputStream in = new ObjectInputStream(FileIn);
                dObjects = (ArrayList<Object>) in.readObject();
                in.close();
                FileIn.close();

            } catch (IOException e2) {
                // TODO: handle exception

                e2.printStackTrace();
                return;

            } catch (ClassNotFoundException c) {
                // TODO: handle exception
                c.printStackTrace();
            }
            br = (int) dObjects.get(0);
            String name = new String(textField.getText());
            char[] pass = passwordField.getPassword();
            String password = new String(pass);
            ArrayList<User> rUsers = new ArrayList<User>();
            User[] rUsers2 = new User[br1];
            rUsers.add(new User(name, password));
            System.out.println(br);
            System.out.println(rUsers.size());
            rUsers2[br] = rUsers.get(0);
            br++;
            br1++;
            ArrayList<Object> data = new ArrayList<Object>();
            data.add(br);
            data.add(br1);
            data.add(rUsers2);
            try {

                FileOutputStream fileOutputStream = new FileOutputStream("users.ser");
                ObjectOutputStream out = new ObjectOutputStream(fileOutputStream);
                out.writeObject(data);
                fileOutputStream.close();
                System.out.println("Yes");

            } catch (IOException e2) {

                e2.printStackTrace();

            }
            Login nw = new Login();
            nw.Login1();
            frmRegistrate.dispose();

        }
    });
String name = new String(textField.getText());
            String password = new String(passwordField.getPassword());
            int b = 0;
            ArrayList<Object> dObjects = new ArrayList<Object>();
            try {

                FileInputStream FileIn = new FileInputStream("users.ser");
                ObjectInputStream in = new ObjectInputStream(FileIn);
                dObjects = (ArrayList<Object>) in.readObject();
                in.close();
                FileIn.close();

            } catch (IOException e2) {
                // TODO: handle exception

                e2.printStackTrace();
                return;

            } catch (ClassNotFoundException c) {
                // TODO: handle exception
                c.printStackTrace();
            }
            int rebr = (int) dObjects.get(0);
            User[] lUsers = new User[rebr];
            lUsers = (User[]) dObjects.get(2);
            System.out.println(rebr);
            System.out.println(lUsers);
            while (b < rebr) {

                System.out.println(lUsers[b].getName());

                if (lUsers[b].getName().equals(name) && lUsers[b].getPassword().equals(password)) {

                    b = rebr;
                    frmLogin.dispose();
                    Menu nw = new Menu();
                    nw.Menu1();

                } else {
                    b++;
                }

            }

        }
    });
intbr1=4,br=0;
ArrayList dObjects=新的ArrayList();
试一试{
FileInputStream FileIn=newfileinputstream(“users.ser”);
ObjectInputStream in=新的ObjectInputStream(FileIn);
.readObject()中的dObjects=(ArrayList);
in.close();
FileIn.close();
}捕获(IOE2异常){
//TODO:处理异常
e2.printStackTrace();
返回;
}捕获(ClassNotFoundException c){
//TODO:处理异常
c、 printStackTrace();
}
br=(int)dObjects.get(0);
字符串名称=新字符串(textField.getText());
char[]pass=passwordField.getPassword();
字符串密码=新字符串(通过);
ArrayList rUsers=新的ArrayList();
用户[]rUsers2=新用户[br1];
添加(新用户(名称、密码));
系统输出打印项次(br);
System.out.println(rUsers.size());
rUsers2[br]=rUsers.get(0);
br++;
br1++;
ArrayList数据=新的ArrayList();
添加数据(br);
添加数据(br1);
添加数据(rUsers2);
试一试{
FileOutputStream FileOutputStream=新的FileOutputStream(“users.ser”);
ObjectOutputStream out=新的ObjectOutputStream(fileOutputStream);
out.writeObject(数据);
fileOutputStream.close();
System.out.println(“是”);
}捕获(IOE2异常){
e2.printStackTrace();
}
Login nw=新登录();
nw.Login1();
frmregistate.dispose();
}
});
反序列化注册配置文件的代码

int br1 = 4, br = 0;
            ArrayList<Object> dObjects = new ArrayList<Object>();
            try {

                FileInputStream FileIn = new FileInputStream("users.ser");
                ObjectInputStream in = new ObjectInputStream(FileIn);
                dObjects = (ArrayList<Object>) in.readObject();
                in.close();
                FileIn.close();

            } catch (IOException e2) {
                // TODO: handle exception

                e2.printStackTrace();
                return;

            } catch (ClassNotFoundException c) {
                // TODO: handle exception
                c.printStackTrace();
            }
            br = (int) dObjects.get(0);
            String name = new String(textField.getText());
            char[] pass = passwordField.getPassword();
            String password = new String(pass);
            ArrayList<User> rUsers = new ArrayList<User>();
            User[] rUsers2 = new User[br1];
            rUsers.add(new User(name, password));
            System.out.println(br);
            System.out.println(rUsers.size());
            rUsers2[br] = rUsers.get(0);
            br++;
            br1++;
            ArrayList<Object> data = new ArrayList<Object>();
            data.add(br);
            data.add(br1);
            data.add(rUsers2);
            try {

                FileOutputStream fileOutputStream = new FileOutputStream("users.ser");
                ObjectOutputStream out = new ObjectOutputStream(fileOutputStream);
                out.writeObject(data);
                fileOutputStream.close();
                System.out.println("Yes");

            } catch (IOException e2) {

                e2.printStackTrace();

            }
            Login nw = new Login();
            nw.Login1();
            frmRegistrate.dispose();

        }
    });
String name = new String(textField.getText());
            String password = new String(passwordField.getPassword());
            int b = 0;
            ArrayList<Object> dObjects = new ArrayList<Object>();
            try {

                FileInputStream FileIn = new FileInputStream("users.ser");
                ObjectInputStream in = new ObjectInputStream(FileIn);
                dObjects = (ArrayList<Object>) in.readObject();
                in.close();
                FileIn.close();

            } catch (IOException e2) {
                // TODO: handle exception

                e2.printStackTrace();
                return;

            } catch (ClassNotFoundException c) {
                // TODO: handle exception
                c.printStackTrace();
            }
            int rebr = (int) dObjects.get(0);
            User[] lUsers = new User[rebr];
            lUsers = (User[]) dObjects.get(2);
            System.out.println(rebr);
            System.out.println(lUsers);
            while (b < rebr) {

                System.out.println(lUsers[b].getName());

                if (lUsers[b].getName().equals(name) && lUsers[b].getPassword().equals(password)) {

                    b = rebr;
                    frmLogin.dispose();
                    Menu nw = new Menu();
                    nw.Menu1();

                } else {
                    b++;
                }

            }

        }
    });
String name=新字符串(textField.getText());
字符串密码=新字符串(passwordField.getPassword());
int b=0;
ArrayList dObjects=新的ArrayList();
试一试{
FileInputStream FileIn=newfileinputstream(“users.ser”);
ObjectInputStream in=新的ObjectInputStream(FileIn);
.readObject()中的dObjects=(ArrayList);
in.close();
FileIn.close();
}捕获(IOE2异常){
//TODO:处理异常
e2.printStackTrace();
返回;
}捕获(ClassNotFoundException c){
//TODO:处理异常
c、 printStackTrace();
}
int-rebr=(int)dObjects.get(0);
用户[]lUsers=新用户[rebr];
lUsers=(用户[])dObjects.get(2);
系统输出打印项次(rebr);
系统输出打印LN(lUsers);
while(b
我希望有人能帮我解决这个问题。
如果我的问题很奇怪,我很抱歉,但我在这个论坛和编程方面都是新手

如果这不是错误的原因(我们不知道你的错误在哪里,因为你没有给出堆栈跟踪),那么它将是

    ArrayList<Object> data = new ArrayList<Object>();
    data.add(br);
    data.add(br1);
    data.add(rUsers2);
ArrayList data=new ArrayList();
添加数据(br);
添加数据(br1);
添加数据(rUsers2);
Java不知道如何将
int
类型
br
br1
存储为数组列表类型的
对象


在这里发布特定问题之前,您似乎需要更多地阅读java,并在错误上进行更多的谷歌搜索,因为很可能您遇到了许多其他人都遇到过的错误。

您需要包含错误消息和/或stacktrace。