public void readList () {
try {
FileOutputStream writeData = new FileOutputStream("Accounts.txt");
ObjectOutputStream writeStream = new ObjectOutputStream(writeData);
writeStream.writeObject(AccountCredentials);
writeStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
public void writeList() {
try {
FileInputStream readData = new FileInputStream("Accounts.txt");
ObjectInputStream readStream = new ObjectInputStream(readData);
AccountCredentials = (ArrayList <Accounts>) readStream.readObject();
readStream.close();
System.out.println(AccountCredentials.size());
}
catch (Exception e) {
e.printStackTrace();
}
}我的readList方法运行得很好,我在文件中有¬í sr java.util.ArrayListxÒ™Ça I sizexp w。我的writeList没有。我在Netbeans文件夹中有一个学校文件夹,在主目录中是Accounts.txt。我需要指定吗?我的Java文件在School/src中。它总是说我的列表大小是0
发布于 2021-06-07 22:09:58
你能分享你得到的异常或堆栈跟踪并粘贴到这里吗?另外,我强烈建议不要使用平面文件存储帐户凭证,而是使用任何身份管理解决方案和数据库驱动的帐户管理。您是否还尝试调试以下代码行"ObjectInputStream readStream = new ObjectInputStream(readData);“
https://stackoverflow.com/questions/67873141
复制相似问题