Results 1 to 3 of 3

Thread: Copy a file

  1. #1

    Thread Starter
    Hyperactive Member rockies1's Avatar
    Join Date
    Jul 1999
    Location
    Stuck at work
    Posts
    375

    Copy a file

    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!
    Morgan
    [email protected] - Home
    [email protected] - Work
    Using VB6 SP6 but trying to learn VB2005EE

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width