renameTo for Directories on Solaris

E

ebresie

I've been attempting to rename a directory on Solaris 8 and continue to
have problems.

I read other threads that mention it is not possible to do when moving
between partitions on Solaris, but I am renaming to the same
paritition.

I am basically attempting the following:

File oldName = new File("/opt/OldDirectoryName");
File newName = new File("/opt/NewDirectoryName");

if ( oldName.renameTo( newName ) )
// Successfully renamed
else
// Failed to rename

For some reason I seem to continually be unable to do this.

Any ideas?

Eric
 
T

Thomas Fritsch

I am basically attempting the following:

File oldName = new File("/opt/OldDirectoryName");
File newName = new File("/opt/NewDirectoryName");

if ( oldName.renameTo( newName ) )
// Successfully renamed
else
// Failed to rename

For some reason I seem to continually be unable to do this.

Any ideas?

What happens if you try it in a shell
mv /opt/OldDirectoryName /opt/NewDirectoryName
? Do you get an error message from the shell?
I would guess, you'll get something like "permission denied", because the
operation requires write-access to the /opt directory.
 
J

JScoobyCed

Thomas said:
What happens if you try it in a shell
mv /opt/OldDirectoryName /opt/NewDirectoryName
? Do you get an error message from the shell?
I would guess, you'll get something like "permission denied", because the
operation requires write-access to the /opt directory.

It's a good suggestion, but not necessary the right thing. I got similar
problem on FreeBSD (ok, Mac OS X :) ). I could rename or move or delete
my file with the shell command line, but not from Java File.renameTo(File)
Unfortunately at that time I was in a hurry to close the project and did
"the dirty Harry way" (shame on me):
FileInputStream on the oldFile
FileOutputStream on the new file
read from old file arrays of byte[] and write them to the output.

It has the advantage of working, but in term of performances, it is
really bad. My project didn't need performance, so it was ok, but...
 
E

ebresie

Does that work for directories as well?

I'm not really up on java security configuration processes, but could
this in any way have to do with security policy for my java
environment?

Eric
 
E

ebresie

Yup...this seems to be the case.

I had performed the rename step in a perl script previously, which I
was attempting to duplicated in java. The perl script was running as
root at boot time, so it did not exhibit this problem.

Eric
 
T

Thomas Fritsch

Does that work for directories as well?

I'm not really up on java security configuration processes, but could
this in any way have to do with security policy for my java
environment?
If renameFile() fails because of java security, then you would get a
SecurityException. If it fails because of another reason (OS denies
permission), then you get "false" as return-value. So you can
distinguish between these causes easily.
 

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

Forum statistics

Threads
474,434
Messages
2,571,688
Members
48,796
Latest member
Greg L.

Latest Threads

Top