I need to download some .xls files from a web site. Since they are kind of big, about 17MB each, I rather not use BufferedReader to open them, read in the data and then write data to a local file. I noticed that FileChannel class has some really nice features, which makes transfer big files much faster and easier. But I cannot figure out how to use FileChannel with online file's URL, instead of local file. Have someone ever done these before? Besides FileChannel and read/write data using BufferedReader, does anyone have any other suggestions on downloading big files in java? Thanks a lot.
Here's the documentation and some examples of NIO. I think it's overkill if you just want to copy a file from a URL. If your concern is the performance of reading the whole file in then writing it out why don't you read a chunk then write a chunk? I'd use Buffered*putStream rather than BufferedReader, as BufferedReader is for working with character data and I don't know that .xls files are all char data.
Thanks everyone. I am using BufferedReader.readLine(), not read char. About the nio package, I think since I am download from a web server, not local disk, I cannot use FileChannel. I tried to use SocketChannel, but the problem is I cannot get the port number from the server. I guess since that web site is directly connected with underlying database, maybe the server won't let anyone to directly download or upload stuffs to it, so they can pretect their database. I can accept the current performance, which is 3-4 minutes for one file (17MB). I just need to let the computer run overnight for the 120 files. Thanks anyway.
Your mother was a hamster and your father was a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth