Problem with java Rename function in solaris platform.

D

drajibneed

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.
 
R

Roedy Green

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
 
R

Raju

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...............
 
C

Chris Uppal

Raju 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.

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.)
 
T

Thomas Weidenfeller

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
 
R

Raju

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...
 
R

Raju

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????
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 
N

Nigel Wade

Raju said:
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.
 
E

EJP

Raju said:
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.
 
R

Roedy Green

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
 
D

Dimitri Maziuk

Roedy Green sez:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top