• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with FileChannel

 
Sally ZX
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Sally!
Look at this post to see if it is of any help.
 
Sally ZX
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!