Problem with java Rename function in solaris platform.

Discussion in 'Java' started by drajibneed@gmail.com, Mar 10, 2006.

  1. Guest

    when a external disk is mounted on Sun Solaris system its get
    transparent to the local File sytem.
    While trying to copy a File/files(using Java) from local file system to
    the external disk,
    the operation was quite successfull,but in case of moving the
    files(using rename() function) from local to external disk,operation
    failed.Are there any methods/procedures or any kind of solution in JDK
    1.4 or above to do the operation smoothly.can anyone help me to find
    this????Thanx in advance.
     
    , Mar 10, 2006
    #1
    1. Advertising

  2. Roedy Green Guest

    On 9 Mar 2006 22:09:44 -0800, wrote, quoted or
    indirectly quoted someone who said :

    >the operation was quite successfull,but in case of moving the
    >files(using rename() function) from local to external disk,operation


    Rename is just that. It goes into the directory and changes the name
    of the file leaving the data part alone. This gives the illusion of
    moving the file to a different spot on the same drive. It is not
    intended for moving files from drive to drive. A move is a copy
    followed by delete.

    There are several ways to move files.

    1. use http://mindprod.com/products.html#FILETRANSFER to copy files
    then use File.delete.

    2. exec a platform specific script that does it. see
    http://mindprod.com/jgloss/jgloss/exec.html.

    3. use FileInputStreams to such files into ram and squirt them out
    with FileOutputStreams. Works if files not that big.
    http://mindprod.com/applets/fileio.html


    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 10, 2006
    #2
    1. Advertising

  3. Raju Guest

    I giving here the code part:
    ------------------------------------------
    String l_stTMPCopyFile = l_stPERmtpath + "/" + l_stTMPFileNm + ".TMP";
    File l_TMPFile = new File(l_stTMPCopyFile);
    boolean l_bTMPCopy = l_stSrcFileNm.renameTo(l_TMPFile);
    ........................................................................................................................................

    here actually the renameTo function failed while trying to move the
    files local disk to the externally mounted disk in Solaris platform.But
    in case of moving files within the local disk the function worked
    properly.
    Thanx for the reply...............
    Roedy Green wrote:

    > On 9 Mar 2006 22:09:44 -0800, wrote, quoted or
    > indirectly quoted someone who said :
    >
    > >the operation was quite successfull,but in case of moving the
    > >files(using rename() function) from local to external disk,operation

    >
    > Rename is just that. It goes into the directory and changes the name
    > of the file leaving the data part alone. This gives the illusion of
    > moving the file to a different spot on the same drive. It is not
    > intended for moving files from drive to drive. A move is a copy
    > followed by delete.
    >
    > There are several ways to move files.
    >
    > 1. use http://mindprod.com/products.html#FILETRANSFER to copy files
    > then use File.delete.
    >
    > 2. exec a platform specific script that does it. see
    > http://mindprod.com/jgloss/jgloss/exec.html.
    >
    > 3. use FileInputStreams to such files into ram and squirt them out
    > with FileOutputStreams. Works if files not that big.
    > http://mindprod.com/applets/fileio.html
    >
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Java custom programming, consulting and coaching.
     
    Raju, Mar 10, 2006
    #3
  4. Chris Uppal Guest

    Raju wrote:

    > here actually the renameTo function failed while trying to move the
    > files local disk to the externally mounted disk in Solaris platform.But
    > in case of moving files within the local disk the function worked
    > properly.


    Yes that's exactly what you should expect. Renaming works to any name and
    directory within the same filesystem, but does not and cannot work when the
    target is on a different filesystem[*]. To move a file to another filesystem
    requires a copy then a delete.

    It's ages since I touched Solaris, but I think you'd get the same kind of
    failure if you used the command line utility "mv":

    mv /where/ever/file1 /some/where/else/file2

    if "/where/ever" and "/some/where/else" were on different filesystems.

    -- chris

    ([*] the rules are platform dependent, of course, but that's the typical case
    on Unix and Windows.)
     
    Chris Uppal, Mar 10, 2006
    #4
  5. Top-posting removed.

    Raju wrote:
    > I giving here the code part:
    > ------------------------------------------
    > String l_stTMPCopyFile = l_stPERmtpath + "/" + l_stTMPFileNm + ".TMP";
    > File l_TMPFile = new File(l_stTMPCopyFile);
    > boolean l_bTMPCopy = l_stSrcFileNm.renameTo(l_TMPFile);
    > .......................................................................................................................................


    Hungarian Notation :-(

    As for renameTo() working or not, here is a quote from the
    documentation, which by the way you should really check out:

    | Many aspects of the behavior of this method are inherently
    | platform-dependent: The rename operation might not be able to move a
    | file from one filesystem to another, it might not be atomic, and it
    | might not succeed if a file with the destination abstract pathname
    | already exists.

    In other words, it is not supposed to work in the particular case. If it
    doesn't work, it is well within the specifications and there is probably
    nothing you can do to make the method work. Implement something else.

    /Thomas

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Mar 10, 2006
    #5
  6. Raju Guest

    Thanx Roedy for the reply...But my problem is in the renameTo()
    function.I'm giving here the code part:
    ------------------------------------------
    String l_stTMPCopyFile = l_stPERmtpath + "/" + l_stTMPFileNm + ".TMP";
    File l_TMPFile = new
    File(l_stTMPCopyFile);
    boolean l_bTMPCopy =
    l_stSrcFileNm.renameTo(l_TMPFile);
    ........................................................................................................................................

    here actually the renameTo function failed while trying to move the
    files local disk to the externally mounted disk in Solaris platform.But
    in case of moving files within the local disk the function worked
    properly...
     
    Raju, Mar 10, 2006
    #6
  7. Raju Guest

    Thanx a lot Chris...
     
    Raju, Mar 10, 2006
    #7
  8. Raju Guest

    Thanx alot Thomas....But one thing,both solaris and java are product
    from Sun,still renameTo() function will not work for different
    filesystem in solaris???is it a operating system flaw????
     
    Raju, Mar 10, 2006
    #8
  9. Roedy Green Guest

    On 10 Mar 2006 01:55:51 -0800, "Raju" <> wrote,
    quoted or indirectly quoted someone who said :

    >here actually the renameTo function failed while trying to move the
    >files local disk to the externally mounted disk in Solaris platform.But
    >in case of moving files within the local disk the function worked
    >properly.


    that is exactly what it is supposed to do.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 10, 2006
    #9
  10. Roedy Green Guest

    On Fri, 10 Mar 2006 10:09:47 -0000, "Chris Uppal"
    <-THIS.org> wrote, quoted or indirectly
    quoted someone who said :

    >It's ages since I touched Solaris, but I think you'd get the same kind of
    >failure if you used the command line utility "mv":


    "move" in 4NT does a rename if on the source and target are on the
    same drive or a copy/delete if not. I can't recall ever encountering
    a "rename" that ever did a copy/delete.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 10, 2006
    #10
  11. Nigel Wade Guest

    Raju wrote:

    > Thanx alot Thomas....But one thing,both solaris and java are product
    > from Sun,still renameTo() function will not work for different
    > filesystem in solaris???is it a operating system flaw????


    No. It's a feature, and very definitely a feature not a bug. I don't know of an
    OS where a rename can be done across filesystems.

    Renaming a file does not move it in any way, even though the UNIX command name
    "mv" gives the impression that it might. Only the filename entry is moved from
    one directory into another - the file contents do not move on the disk. To
    transfer a file from one filesystem to another filesystem requires copying the
    actual file contents, something which rename does not do. Rename and move are
    two different operations.

    Some UNIXs now implement the mv command in such a way that if the destination is
    on another filesystem a real move (copy/delete) is done rather than a rename.
    But the Java renameTo() function is simply a rename.

    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
     
    Nigel Wade, Mar 13, 2006
    #11
  12. EJP Guest

    Raju wrote:

    > Thanx alot Thomas....But one thing,both solaris and java are product
    > from Sun,still renameTo() function will not work for different
    > filesystem in solaris???is it a operating system flaw????


    Most operating systems support a system call to rename files and these
    are what Java uses. To my knowledge only DOS, Windows, and OS/2 support
    a system call to *move* files: i.e. Unix, Solaris, HP/UX, Linux,
    NetWare, RSX/11, RT/11, RSTS/E, Guardian, COSMOS, ... do not. My
    information is incomplete. Some of these do support a *command* which
    does so, but the JVM is not in the business of running commands to
    execute APIs: nor should it be.
     
    EJP, Mar 13, 2006
    #12
  13. Roedy Green Guest

    On Mon, 13 Mar 2006 23:56:29 GMT, EJP
    <> wrote, quoted or indirectly quoted
    someone who said :

    >o my knowledge only DOS, Windows, and OS/2 support
    >a system call to *move* files


    In Windows, there is a command processor move command, but from the
    OS level, I think all you have is rename. I am completely sure of that
    for DOS, less for Windows. With big ram machines you can more
    efficiently move files your self using FileTransfer class with
    whacking big buffers, usually big enough for the entire file in one
    i/o.

    See http://mindprod.com/products1.html#FILETRANSFER

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Mar 14, 2006
    #13
  14. Roedy Green sez:
    > On Mon, 13 Mar 2006 23:56:29 GMT, EJP
    ><> wrote, quoted or indirectly quoted
    > someone who said :
    >
    >>o my knowledge only DOS, Windows, and OS/2 support
    >>a system call to *move* files

    >
    > In Windows, there is a command processor move command, but from the
    > OS level, I think all you have is rename. I am completely sure of that
    > for DOS, less for Windows.


    The difference between "move" and "rename" is that rename does not
    actually move anything. It only changes directory entries/i-nodes/
    whatever information structures the fs has. Which is why it only
    works within a single filesystem; to move across fs boundaries you
    have to physically move the d-nodes as well.

    Dima
    --
    The wombat is a mixture of chalk and clay used for respiration. -- MegaHal
     
    Dimitri Maziuk, Mar 14, 2006
    #14
  15. EJP Guest

    Roedy Green wrote:
    >>To my knowledge only DOS, Windows, and OS/2 support
    >>a system call to *move* files

    >
    >
    > In Windows, there is a command processor move command, but from the
    > OS level, I think all you have is rename. I am completely sure of that
    > for DOS, less for Windows.


    For DOS I agree, I was dreaming. For Windows see
    http://msdn.microsoft.com/library/en-us/fileio/fs/copyfile.asp
     
    EJP, Mar 14, 2006
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jcc
    Replies:
    15
    Views:
    4,768
    Nigel Wade
    May 12, 2006
  2. Coca
    Replies:
    15
    Views:
    676
    Alan Balmer
    Jan 14, 2004
  3. zoltan
    Replies:
    2
    Views:
    422
    zoltan
    Mar 13, 2006
  4. jing
    Replies:
    1
    Views:
    334
    mlimber
    Dec 8, 2005
  5. Andy K
    Replies:
    0
    Views:
    137
    Andy K
    May 27, 2004
Loading...

Share This Page