i am trying to develop an application to transfer large files over a network.Am trying to implement the same splitting files into chunks how to split a large file into chunks of 50kb each? And how to put it back to original on basis of hashcode( for error control)?
Asked
Active
Viewed 2,198 times
0
-
This may be helpful http://stackoverflow.com/q/10864317/1393766 – Pshemo Jul 27 '15 at 17:06
-
1Which transfer protocol are you planning to use for the chunks? If you go TCP you do not need error control, TCP does this for you. – alk Jul 27 '15 at 17:10
1 Answers
0
i know this is not really what you asked for but you can transfer large files like this Sender :
try
{
ss = new ServerSocket(9244); // try to open ServerSocket
ready =true;
}
catch(Exception e)
{
}
Socket bs = ss.accept(); // reciever joins
OutputStream out = bs.getOutputStream();
fis = new FileInputStream(f); // you open fileinputstream of the file you want to send
int x = 0;
while (true) {
x = fis.read();
if (x == -1) { // until fis.read() doesn't return -1 wich means file is completly read write bytes out
break;
}
out.write(x);
}
fis.close();
out.close();
bs.close();
ss.close();
Reciever:
try {
Socket socket = new Socket("127.0.0.1",9244); // connect to server
InputStream in = socket.getInputStream();
FileOutputStream fos = new FileOutputStream(f);
int x = 0;
while (true) {
x = in.read();
if (x == -1) { // write data into file until in.read returns "-1"
break;
}
fos.write(x);
}
in.close();
fos.close();
socket.close();
hope this was a little helpful

L4B0MB4
- 151
- 1
- 11
-
-
You could at least have taken the burden to provide an example using this implemenation of `read()`: http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read%28byte[]%29 – alk Jul 28 '15 at 18:00
-
-
2Fair enough, wasn't ment offensive either ... just didn't understand .. ;) – alk Jul 28 '15 at 18:21