• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Need help with FileChannel

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic