package com.javapages4all;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
/**
*
* @author Rajeswararao (JavaPages4All)
*
*/
public class FileDownload {
public static void main(String args[]) throws IOException {
BufferedInputStream buffInputStream=null;
FileOutputStream fileOutputStream=null;
BufferedOutputStream buffOutputStream=null;
try {
buffInputStream= new BufferedInputStream(new URL("File Url").openStream());
fileOutputStream = new FileOutputStream("D://JavaPage4All.pdf");
buffOutputStream = new BufferedOutputStream(fileOutputStream,1024);
byte data[] = new byte[1024];
int length;
while ((length = buffInputStream.read(data)) > 0) {
buffOutputStream.write(data, 0, length);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(buffOutputStream != null)
buffOutputStream.close();
if(fileOutputStream != null)
fileOutputStream.close();
if(buffInputStream != null)
buffInputStream.close();
}
}
}
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
/**
*
* @author Rajeswararao (JavaPages4All)
*
*/
public class FileDownload {
public static void main(String args[]) throws IOException {
BufferedInputStream buffInputStream=null;
FileOutputStream fileOutputStream=null;
BufferedOutputStream buffOutputStream=null;
try {
buffInputStream= new BufferedInputStream(new URL("File Url").openStream());
fileOutputStream = new FileOutputStream("D://JavaPage4All.pdf");
buffOutputStream = new BufferedOutputStream(fileOutputStream,1024);
byte data[] = new byte[1024];
int length;
while ((length = buffInputStream.read(data)) > 0) {
buffOutputStream.write(data, 0, length);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(buffOutputStream != null)
buffOutputStream.close();
if(fileOutputStream != null)
fileOutputStream.close();
if(buffInputStream != null)
buffInputStream.close();
}
}
}
No comments:
Post a Comment