Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    You are working with Java objects not with disk files. The objects can be used to manipulate disk files.
    The contents of the Java object don't change as you expect.
    If you want a File object with some name, create a new object with that name.

  2. #22
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    The code does create the bren.txt file on disk and then renames it to john.txt (although if it failed, you'd have trouble finding out why because you ignore any exceptions).

    What you have to remember is that the File class is a Java object that stores a name, it doesn't actually represent a disk file. It can manipulate a file on disk, such as creating one with the name it holds, or renaming it to another name that you supply. The File.rename(..) method just uses the name of the File argument you give it to rename the disk file - but it doesn't change the contents of either File object, which still keep their original names. If you want to mess with the renamed file, you should keep a reference to the File object you passed to the rename method.

    It is a bit counter-intuitive, but it just shows that File isn't a direct link to a disk file, but just a name that it can use to do disk file operations.

    Java 7 has a whole new set of File operations which should make this stuff a lot simpler to use and understand.

    ETA - oops, Norm got there first... !

  3. #23
    mrbrendano is offline Member
    Join Date
    Jul 2011
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    You are working with Java objects not with disk files. The objects can be used to manipulate disk files.
    The contents of the Java object don't change as you expect.
    If you want a File object with some name, create a new object with that name.

    thats it!! Thats what i needed to hear! haha!! Think i need to get my head around objects a bit more!

    Norm thanks a bunch for all your help!!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  2. Replies: 0
    Last Post: 08-14-2010, 10:09 AM
  3. Changing Existing Zip file using java
    By narayanan.1985 in forum Advanced Java
    Replies: 1
    Last Post: 09-30-2009, 08:27 PM
  4. Replies: 1
    Last Post: 10-16-2008, 09:56 PM
  5. Reading Binary File and Changing data
    By janakiram.attuluri in forum Advanced Java
    Replies: 1
    Last Post: 12-21-2007, 10:10 AM

Posting Permissions

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