There is an online file (such as http://www.example.com/information.asp) I need to grab and save to a directory. I know there are several methods for grabbing and reading online files (URLs) line-by-line, but is there a way to just download and save the file using Java?
There is an online file (such as http://www.example.com/information.asp ) I need to grab and
Share
Give Java NIO a try:
Using
transferFrom()is potentially much more efficient than a simple loop that reads from the source channel and writes to this channel. Many operating systems can transfer bytes directly from the source channel into the filesystem cache without actually copying them.Check more about it here.
Note: The third parameter in transferFrom is the maximum number of bytes to transfer.
Integer.MAX_VALUEwill transfer at most 2^31 bytes,Long.MAX_VALUEwill allow at most 2^63 bytes (larger than any file in existence).