how to improve transfering file's efficiency

J

JTL.zheng

I have write program for client to client file transmission
but it seems unefficient ,the transmission speed is low
and it take too much CPU resource

here are the codes(sender's and receiver's)
are there some ways to improve it about the transfer speed and cup?


sender's code:
-------------------------------------------------------
input_file = new BufferedInputStream(new FileInputStream(file));
output_file = new
BufferedOutputStream(socket_file.getOutputStream());

byte[] buffer = new byte[10240];
int readed;
while ( (readed = input_file.read(buffer)) != -1) {
output_file.write(buffer, 0, readed);
}

output_file.flush();
-------------------------------------------------------


receiver's code:
-------------------------------------------------------
output_file = new BufferedOutputStream(new
FileOutputStream(file));
input_file = new
BufferedInputStream(socket_file.getInputStream());

byte[] buffer = new byte[10240];
int readed;
while ( (readed = input_file.read(buffer)) != -1) {
output_file.write(buffer, 0, readed);
}

output_file.flush();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top