Archived

This topic is now archived and is closed to further replies.

Jakarta

[java] copying files in java

Recommended Posts

I need to copy a file (its a url from a website) to a file on my computer. I am trying to figure out how to do this. I found code for copying it with bytes but that messes up the file somewhat.... I want an exact copy of the original file. code is highly appreciated. thanks,

Share this post


Link to post
Share on other sites
You want to copy a URL or an actual file on the Internet?

Either way, it''s basic file I/O. See the FAQ for the link to the Java tutorial.

Share this post


Link to post
Share on other sites
I want to copy an actual file. I tried a few basic input ouput methods. and it always messed up the file a bit, as I said.

Share this post


Link to post
Share on other sites
If you post some code we can probably spot your error. If you are on a Windows machine and write out a ''\r'' by itself or a ''\n'' by itself, then you will see and odd character in notepad. You need to use the ''\r\n'' pair to get a proper new line.

In your case, if you are reading in with readLine, then getting the bytes, then writing it out, you will lose information because readLine() strips off the new line characters.



First make it work, then make it fast. --Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

Share this post


Link to post
Share on other sites