Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Problem with java Rename function in solaris platform.

Thread view: 
drajibneed@gmail.com - 10 Mar 2006 06:09 GMT
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.
Roedy Green - 10 Mar 2006 07:03 GMT
>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

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Raju - 10 Mar 2006 09:55 GMT
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...............

> >the operation was quite successfull,but in case of moving the
> >files(using rename() function) from local to external disk,operation
[quoted text clipped - 20 lines]
> Canadian Mind Products, Roedy Green.
> http://mindprod.com Java custom programming, consulting and coaching.
Chris Uppal - 10 Mar 2006 10:09 GMT
> 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.)
Raju - 10 Mar 2006 10:39 GMT
Thanx a lot Chris...
Roedy Green - 10 Mar 2006 15:18 GMT
On Fri, 10 Mar 2006 10:09:47 -0000, "Chris Uppal"
<chris.uppal@metagnostic.REMOVE-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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Thomas Weidenfeller - 10 Mar 2006 10:19 GMT
Top-posting removed.

> 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

Signature

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/

Raju - 10 Mar 2006 10:46 GMT
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????
Nigel Wade - 13 Mar 2006 11:05 GMT
> 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.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

EJP - 14 Mar 2006 00:56 GMT
> 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.
Roedy Green - 14 Mar 2006 02:18 GMT
On Mon, 13 Mar 2006 23:56:29 GMT, EJP
<esmond.not.pitt@not.bigpond.com> 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

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Dimitri Maziuk - 14 Mar 2006 18:42 GMT
Roedy Green sez:
> On Mon, 13 Mar 2006 23:56:29 GMT, EJP
><esmond.not.pitt@not.bigpond.com> wrote, quoted or indirectly quoted
[quoted text clipped - 6 lines]
> 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
Signature

The wombat is a mixture of chalk and clay used for respiration.      -- MegaHal

EJP - 15 Mar 2006 00:09 GMT
>>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
Roedy Green - 10 Mar 2006 15:16 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Raju - 10 Mar 2006 10:35 GMT
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...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.