基于Java Socket的文件UpLoad代码

pytorch中的wheel文件 whl 文件是 Python 的一个软件包分发格式,用于在 Python 中安装软件包。它是 Python Wheel 的缩写,也被称为 wheel 文件。这种文件格式旨在简化 Python 软件包的安装和分发。对于 PyTorch 而言,它提供了预编译的 .whl 文件,您可以通过 pip 安装这些文件来快速方便地安装 PyTorch。这些 .whl 文件是已经编译好的二进制分发文件,可以直接安装在您的 Python 环境中,而无需再进行编译。 阅读详情

写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




写了份文件对传的简单代码,可以把本地文件夹里的文件传递到Server端。

Server端代码:

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class FileUpLoadProjServer extends Thread {

 public FileUpLoadProjServer(Socket s, String c) throws IOException {
 }

 public void run() {
 }

 public static void main(String[] args) {
  try {
   ServerSocket server = new ServerSocket(8110);
   Socket connection = null;
   while (true) {
    try {
     connection = server.accept();
     InputStreamReader in = new InputStreamReader(connection
       .getInputStream());

     long time = System.currentTimeMillis();
     String t = "C://temp_" + time;
     File myFile = null;
     if ((new File(t).mkdir())) {
      myFile = new File(t + "//temp.txt");
     } else {
      System.out.println("Create folder failed!");
     }

     FileOutputStream fos = new FileOutputStream(myFile);

     int ch = 0;

     while ((ch = in.read()) != -1) {
      System.out.print((char) ch);
      fos.write(ch);
     }
     fos.close();
     connection.close();
    } catch (IOException ioe) {
     System.err.println(ioe);
    } finally {
     try {
      if (connection != null)
       connection.close();
     } catch (IOException e) {
     }
    }
   }
  } catch (IOException ee) {
   System.err.println(ee);
  }
 }
}

 

Client端代码:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

public class FileUpLoadProjClient extends Thread {

 private Socket socket;
 private PrintWriter out;
 final int port = 8110;
 String path = "C://src//test";

 public FileUpLoadProjClient(InetAddress addr) {
  try {
   socket = new Socket(addr, port);
  } catch (IOException e) {

  }

  try {
   out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
     socket.getOutputStream())), true);
   start();
  } catch (IOException e) {
   try {
    socket.close();
   } catch (IOException e2) {
   }
  }
 }

 public void run() {
  try {
   File root = new File(path);
   String[] colum = root.list();
   System.out.println("The file's num is :" + colum.length);

   for (int i = 0; i < colum.length; i++) {
    System.out.println("The colum's content is :" + colum[i]);
    String filePath = path + "//" + colum[i];
    System.out.println("The file's absolutePath is :" + filePath);
    FileInputStream fis = new FileInputStream(filePath);
    int ch = 0;

    while ((ch = fis.read()) != -1) {
     System.out.print((char) ch);
     out.write(ch);
    }
    fis.close();
   }
   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    socket.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }

 public static void main(String[] args) throws IOException,
   InterruptedException {
  InetAddress addr = InetAddress.getByName("127.0.0.1");
  new FileUpLoadProjClient(addr);
 }

}

瞎写的,凑合着用吧。




数据资产目录(SailCatalog)和数据地图(SailMap) 笔者接下来准备开发大数据平台(XSailboat)中的数据资产目录(SailCatalog)和数据地图(SailMap)相关的功能,本文用以记录笔者关于此部分功能的概念梳理和主体功能设计。 阅读详情

相关推荐

上一篇: Windows Embedded CE 6.0开发初体验(四)跑个应用程序先
下一篇: 构建基于MVC+Observer模式的、艺术性的移动开发框架(KJAVA版)(二)
techweb
博客等级 码龄19年 226粉丝 3842原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值