我有客户端 - 服务器应用程序,我需要从客户端发送到服务器和服务器上的文字它们必须分开(我将在数据库中使用它们),最好的方法是什么,单独发送每个单词或者可能用服务器上的所有单词划分?
客户端:
//arraylist
ArrayList<String> Arsend = new ArrayList<String>();
send.add("dod");
send.add("sani");
send.add("fred");
//sending
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
out.writeObject(Arsend);
服务器:
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
Object o = in.readObject();
System.out.println(o); //[dod, sani, fred]
答案 0 :(得分:0)
相反:
Object o = in.readObject();
System.out.println(o); //[dod, sani, fred]
使用:
//Cast in.readObject() to ArrayList<String>
ArrayList<String> receivedList = (ArrayList<String>)in.readObject();
//Loop through receivedList using for-each loop and print every String
for(String s : receivedList){
System.out.println(s);
}