- Get the Length of the content.
- Divide it according to any criteria on size etc.
- Multi thread read the file from different ints. and Write them as maybe myfile.part1 .part2 etc
- Read the same files once all downloaded into one single stream and write them to a new file myfile.file
I tried the following code to get the content length.
public Downloader(String path) throws IOException {
int len = 0;
URL url = new URL(path);
URLConnection connectUrl = url.openConnection();
System.out.println(len = connectUrl.getContentLength());
System.out.println(connectUrl.getContentType());
InputStream input = connectUrl.getInputStream();
int i = len;
int c = 0;
System.out.println("=== Content ===");
while (((c = input.read()) != -1) && (--i > 0)) {
System.out.print((char) c);
}
input.close();
}
heres a sample to join the files.
public void join(String FilePath)
{
long leninfile=0,leng=0;
int count=1,data=0;
try
{
File filename=new File(FilePath);
RandomAccessFile outfile = new RandomAccessFile(filename,"rw");
while(true)
{
filename=new File(FilePath + count + ".sp");
if (filename.exists())
{
RandomAccessFile infile = new RandomAccessFile(filename,"r");
data=infile.read();
while(data!=-1)
{
outfile.write(data);
data=infile.read();
}
leng++;
infile.close();
count++;
}
else
{
break;
}
}
outfile.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
Hope it works out for you.