[java] copying files in java

Started by
5 comments, last by Jakarta 20 years ago
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,
Advertisement
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.
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.
Just what sort of "messing up" are you observing?
Was it the newline carraige return thing? Square, whitespace being output, when you open, say in notepad?
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
stuff like that... yeah
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
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]

This topic is closed to new replies.

Advertisement