A
Andrea Francia
I need write a program which download many files from different web sites.
I found that the following code let me download a file:
URL url = new URL("http://www.example.org/file.txt");
URLConnection con = url.openConnection();
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
OutputStream out = new FileOutputStream("C:\\file.txt");
int i = 0;
byte[] bytesIn = new byte[8096];
while ((i = in.read(bytesIn)) >= 0) {
out.write(bytesIn, 0, i);
}
out.close();
in.close();
But it doesn't work if the web site need an authentication.
If I use
I found that the following code let me download a file:
URL url = new URL("http://www.example.org/file.txt");
URLConnection con = url.openConnection();
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
OutputStream out = new FileOutputStream("C:\\file.txt");
int i = 0;
byte[] bytesIn = new byte[8096];
while ((i = in.read(bytesIn)) >= 0) {
out.write(bytesIn, 0, i);
}
out.close();
in.close();
But it doesn't work if the web site need an authentication.
If I use