本帖最后由 黑马张旭明 于 2012-10-31 23:02 编辑
public class Client {
public static void main(String[] args)throws Exception {
Socket s = new Socket(InetAddress.getLocalHost().getHostAddress(),10008);
FileInputStream fis = new FileInputStream("e:\\program\\my.jar");
OutputStream out = s.getOutputStream();
byte[] buf = new byte[1024];
for(int len=0;(len=fis.read(buf))!=-1;){
out.write(buf,0,len);
}
s.shutdownOutput();
InputStream in = s.getInputStream();
byte[] bufIn = new byte[1024];
int num = in.read(bufIn);
System.out.println(new String(buf,0,num));
fis.close();
s.close();
}
}
public class Server {
public static void main(String[] args)throws Exception {
ServerSocket ss = new ServerSocket(10008);
Socket s = ss.accept();
InputStream in = s.getInputStream();
FileOutputStream fos = new FileOutputStream("e:\\my.jar");
byte[] buf = new byte[1024];
for(int len=0;(len=in.read(buf))!=-1;){
fos.write(buf, 0, len);
}
OutputStream out = s.getOutputStream();
out.write("上传成功".getBytes());
fos.close();
s.close();
ss.close();
}
}
看到网络编程就敲了一下老师的代码,结果输出的不是“上传成功”而是
|
|