|
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 FCM = new FileInputStream (filePath );
Int ch = 0;
While (ch = FCM. read ())! =-1 ){
System. out. print (char) ch );
Out. write (ch );
}
FCM. 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 );
}
} |