对方是怎么接收的呢?
你发送的是字符串啊,接收的时候用BufferedReader读取不会丢失吧?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();
}
} }
你发送的是字符串啊,接收的时候用BufferedReader读取不会丢失吧?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();
}
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货