- import java.io.*;
- import java.io.InputStream;
- import java.net.*;
- class UploadFileClient {
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- Socket s=new Socket("127.0.0.1",10006);
- OutputStream out=s.getOutputStream();
- FileInputStream fis=new FileInputStream("a.txt");
- byte[] buf=new byte[1024];
- int len=0;
- while((len=fis.read(buf))!=-1){
- out.write(buf, 0, len);
- }
- System.out.println("hehe ");
-
- s.close();
- }
-
- }
- class UploadFileServer{
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- ServerSocket ss=new ServerSocket(10006);
- FileOutputStream fos=new FileOutputStream("b.txt");
- while(true){
- Socket s=ss.accept();
- InputStream in=s.getInputStream();
- byte[] buf=new byte[1024];
- int len=0;
- while((len=in.read(buf))!=-1){
- fos.write(buf, 0, len);
- }
- ss.close();
- }
-
-
- }
- }
复制代码 上传成功但是报了异常
|
|