62,614
社区成员
发帖
与我相关
我的任务
分享
public static void receiveFile(Socket socket) {
String s ="";
StringBuffer sf = new StringBuffer();
BufferedReader reader;
try {
reader = new BufferedReader(new
InputStreamReader(socket.getInputStream(),"UTF-8"));
while ((s = reader.readLine()) != null){
sf.append(s);
}
System.out.println(sf.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if (socket != null)
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Socket socket = null;
try {
socket = new Socket();
socket.connect(new InetSocketAddress("127.0.0.1", 8433));
PrintWriter out = new PrintWriter(socket.getOutputStream());
out.print("00000044000107D1746573743300000000000000000000000000000033343234323531393836303132303030313300000000000000000000000000000000000000000000");
out.flush();
out.close();
}catch (Exception e) {
e.printStackTrace();
} finally{
if (socket != null)
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}