I must have 4-5 Java books, but I can't find in any of them how to copy a file.
How can I copy a file from one place to another?
Thanks!
Printable View
I must have 4-5 Java books, but I can't find in any of them how to copy a file.
How can I copy a file from one place to another?
Thanks!
I dont think there is a way to directly to copy a file in Java like using the file copy method in VB . you can use createNewFile() and createTempFile() which create new files but dont copy the contents. If you do use createTempFile() use deleateOnExit() to deleate the file when the JVM exits.
I think you have to do this manualy. Depending on what king of data you are copying you want to use a stream from the java.io package. If you get suck or cant figure it out ill be glad to help. :)
Just wanted to post this. it is not a goog idea to read Unicode with a stream, because streams generally read a byte at a time.
And each Unicode character is comprised of two bytes. So what you would have to do is multiply the first byte read, add it to the second byte read and cast it to a char.
For instance:
Code:int b1 = in.read();
int b2 = in.read();
char c = (char) (b1*256 + b2);
So say we have the number 300.
300 in binary is 100101100
So take the first byte which is. 1 = 1
and the second which is 0010 1100 = 44
1 * 256 = 256
256 + 44 = 300
cast 300 to a char and complete!