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 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); } } |