我正在尝试创建一个客户端服务器应用程序,服务器在其中检索电子邮件列表(标识为.txt文件),并通过电子邮件的ArrayList(这是一个对象)发送其所有内容。现在,我在客户端上出现错误,更具体地说是在读取对象的那一行上。这是我的服务器:
File dir = new File(nomeAccount);
String[] tmp = new String[5];
ArrayList<Email> arr = new ArrayList<Email>();
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
int i = 0;
for (File file : dir.listFiles()) {
if (file.isFile()) {
Scanner input = new Scanner(System.in);
input = new Scanner(file);
while (input.hasNextLine()) {
tmp[i++] = input.nextLine();
}
input.close();
}
Date data = df.parse(tmp[4]);
arr.add(new Email((Integer.parseInt(tmp[0])), tmp[1], nomeAccount, tmp[2], tmp[3], data));
i = 0;
}
//PHASE 3: The server sends the ArrayList to the client
try {
ObjectOutputStream objectOutput = new ObjectOutputStream(incoming.getOutputStream());
objectOutput.writeObject(arr);
} catch (IOException e) {
e.printStackTrace();
}
这是客户:
//PHASE 2: The client receives the ArrayList with the emails
ObjectInputStream inStream = new ObjectInputStream(s.getInputStream());
email = (ArrayList<Email>) inStream.readObject();
inStream.close();
我在这里得到错误: ObjectInputStream inStream = new ObjectInputStream(s.getInputStream());
这是错误:
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketException: Socket is closed
at java.net.Socket.getInputStream(Socket.java:903)
at mailbox.DataModel.loadData(DataModel.java:73)
at mailbox.ListController.initModel(ListController.java:28)
at mailbox.MailBox.start(MailBox.java:37)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Exception running application mailbox.MailBox