public static void copy(String url, String filename)
throws MalformedURLException, IOException
{
URL theURL = new URL(url);
File theFile = new File(filename);
// open the URL
BufferedReader in =
new BufferedReader(new InputStreamReader(theURL.openStream()));
// open the file
FileWriter out = new FileWriter(theFile);
// set the size of the character buffer
char[] cbuf = new char[256];
int charsread;
// read off the inputstream into the filewriter
while((charsread = in.read(cbuf)) != -1) {
out.write(cbuf,0,charsread);
}
//flush the filewriter
out.flush();
}
-Lkb
On Mon, 20 May 2002, John Hunter wrote:
>
> How would I use java to fetch a remote url and copy its contents to a
> local file. Being a java novice, I am at sea. Could one of you
> please enlighten me?
>
> outFile = '/tmp/some.dat'
> url = 'http://some.server/some/path/some.dat'
>
> insert some java magic here
>
> Thanks,
> John Hunter
>
> _______________________________________________
> Bits mailing list
> [EMAIL PROTECTED]
> http://www.sugoi.org/mailman/listinfo/bits
>
_______________________________________________
Bits mailing list
[EMAIL PROTECTED]
http://www.sugoi.org/mailman/listinfo/bits