[java] copying files in java
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,
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.
Either way, it''s basic file I/O. See the FAQ for the link to the Java tutorial.
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.
Was it the newline carraige return thing? Square, whitespace being output, when you open, say in notepad?
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement