JAVA SOCKET的I/O 使用
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
out.close();
in.close();
使用中,又出现问题:
readLine一直读不出东西来,使用read有int;
解决办法:
out.println(s);
out.flush();
强调:一定要使用println,不能是print,readLine是根据换行来判断是否结束,否则读不出来。
ByteArrayOutputStream baos=new ByteArrayOutputStream();
byte[] buffer=new byte[1024];
int len=-1;
while((len = is.read(buffer)!)=-1){
baos.write(buffer,0,len);
}
is.close();
String html =baos.toString();
baos.close();
return html;