Sender
------------------------------------------------------------------------------------------------------------Socket sock = new Socket("127.0.0.1",1326);
File myFile = new File ("./encryp.txt");
byte [] mybytearray = new byte [(int)myFile.length()];
FileInputStream fis = new FileInputStream(myFile);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.read(mybytearray,0,mybytearray.length);
OutputStream os = sock.getOutputStream();
os.write(mybytearray,0,mybytearray.length);
os.flush();
sock.close();
Reciever
------------------------------------------------------------------------------------------------------------int filesize=6022386;
long start = System.currentTimeMillis();
int bytesRead;
int current = 0;
ServerSocket servsock = new ServerSocket(1326);
Socket sock = servsock.accept();
byte [] mybytearray = new byte [filesize];
InputStream is = sock.getInputStream();
FileOutputStream fos = new FileOutputStream("C:/AJs PC/"+nam+".txt");
BufferedOutputStream bos = new BufferedOutputStream(fos);
bytesRead = is.read(mybytearray,0,mybytearray.length);
current = bytesRead;
do {
bytesRead = is.read(mybytearray, current, (mybytearray.length-current));
if(bytesRead >= 0)
current += bytesRead;
} while(bytesRead > -1);
bos.write(mybytearray, 0 , current);
bos.flush();
long end = System.currentTimeMillis();
System.out.println(end-start);
bos.close();
sock.close();
No comments:
Post a Comment