PC Remote Host Program
Send. Java
Import java. AWT. image. databuffer;
Import java. AWT. image. databufferbyte;
Import java. Io. bufferedinputstream;
Import java. Io. bufferedreader;
Import java. Io. bufferedwriter;
Import java. Io. datainputstream;
Import java. Io. dataoutputstream;
Import java. Io. file;
Import java. Io. fileinputstream;
Import java. Io. filenotfoundexception;
Import java. Io. ioexception;
Import java. Io. inputstreamreader;
Import java. Io. outputstream;
Import java. Io. outputstreamwriter;
Import java.net. serversocket;
Import java.net. Socket;
/**
* Filename: Send. Java
* Company: *** Limited (Android) 2012-2015
* Compiler: Eclipse 3.7.1
* Remark: Todo
* Created: 2012-3-5 weeds
* Changed: latecomer
*/
/**
* Filename: Todo
*/
Public class send {
/**
* @ Param ARGs
*/
Static file fname;
Static int Port = 8888;
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Try {
Readfile ("d.txt ");
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
Public static void sendfile (string filename)
{
Fname = new file (filename );
Try {
Fname. createnewfile ();
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
Public static void readfile (string filename) throws ioexception
{
Socket cs = NULL;
Try {
System. Out. println ("waiting for connection ...");
Serversocket Ss = new serversocket (port );
While (true ){
String filepath = "d :\\ yc.rar ";
File Fi = new file (filepath );
System. Out. println ("file length:" + (INT) Fi. Length ());
Cs = ss. Accept ();
System. Out. println ("establish socket link ");
Datainputstream Dis = new datainputstream (New bufferedinputstream (CS. getinputstream ()));
Dis. readbyte ();
Datainputstream fdata = new datainputstream (New bufferedinputstream (New fileinputstream (filepath )));
Dataoutputstream PS = new dataoutputstream (CS. getoutputstream ());
PS. writeutf (Fi. getname ());
PS. Flush ();
PS. writelong (long) Fi. Length ());
PS. Flush ();
Byte [] B = new byte [102400];
While (true ){
Int READ = 0;
If (fdata! = NULL ){
Read = fdata. Read (B );
}
If (read =-1 ){
Return;
}
PS. Write (B, 0, read );
PS. Flush ();
Fdata. Close ();
Dis. Close ();
CS. Close ();
SS. Close ();
}
}
} Catch (exception e ){
// Todo: handle exception
}
}
}