• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 705
  • Last Modified:

file renaming/copying & permissions

Using JDK 1.2 File methods...

1) When you use renameTo() does it overwrite existing files?  If so will it overwrite read-only files?

2) When you use setReadOnly() is there
any way to set a file back to rw?

Thanx,
CJ
0
cheekycj
Asked:
cheekycj
  • 10
  • 8
1 Solution
 
mbormannCommented:
(1) This is checked with the default security manager if installed, I think the default checkWrite() is empty,so implement ur own SM and force the behaviour u want,be sure to override the checkWrite().
0
 
mbormannCommented:
oops i am hitting the submit button sooner ,been getting a bit forgetful lately.

(2) I dont think so in Pure Java,if u find it out pls lemme knwo
0
 
cheekycjAuthor Commented:
OK for 2) is no.

for 1) if it is not set to Read-Only then it will overwrite the file.  That is correct?

CJ
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mbormannCommented:
for (1) I dont know for certain sure but I dont think so but u know for a Application generally u never have a SM in place ,so havea SM in place and have the desired functionality u want,that is what we do in all our subsystems.
0
 
cheekycjAuthor Commented:
SM???
(pardon my ignorance)

CJ
0
 
mbormannCommented:
Security Manager
0
 
cheekycjAuthor Commented:
I guess I could do a 2 step renameTo()

1. if File.Exists() then File.delete()
// deletes the file that would be overwritten.
2. File.renameTo();

If you issue a delete command on a ReadOnly file... does it give an error?

CJ
0
 
mbormannCommented:
CJ ,
I tried it on NT4.0 jdk1.1.5

>>>>>If you issue a delete command on a ReadOnly file... does it give an error?
I deleted the read only file

>>>>>When you use renameTo() does it overwrite existing files?  If so will it overwrite read-only files?

Yes
0
 
cheekycjAuthor Commented:
Thanx for all the help.  Post as answer and I will give you the points.

CJ
0
 
mbormannCommented:
so what r u going to do finally?
0
 
cheekycjAuthor Commented:
I am going to use Unix to do my Security management... give ownership of the application to root but let anyone execute it (so no one can delete any of the config/app files)

Then in the app I am using a 2 step saving mechanism (for files just in case the app crashes)
I save the latest config to a temp.
rename the current config to .bak.
rename the temp to the current.

This way if the app crashes I still have either a temp or a .bak still in place.

Thanx for the help.
CJ
0
 
mbormannCommented:
CJ, u have deleted ur Memory Issues question?

why didnt u leave a comment at that b4 deleting?
0
 
cheekycjAuthor Commented:
No, I haven't deleted it but it dissapeared???  I couldn't find it. I wanted to distribute points.  I found out our final problem was being caused by a Bean called Formula1.

How do I get my question back or find it?

CJ
0
 
mbormannCommented:
Oohs now I remember abt 2 weesk ago suddenly i got 4000 points and one of my pending questions also got deleted ,as it was small fry i let it go.

But u gotta tell the guys at the EE Csutomer service and make ti reappear.

sorry for not remembering this as I wanted to refer to it today for 1 of the URL's for IOStreams

Cheers
;-)
0
 
mbormannCommented:
Ok the URL is
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10235790 

I think that they didnt follow their own practice of pending deleted question notification ,ask them all abt it or see my pending question in my ShowUser/Information on .....

bye
0
 
cheekycjAuthor Commented:
I will post a question at EE's Customer Service.. I don't remember the Question Number but maybe they can dig it up.

CJ
0
 
cheekycjAuthor Commented:
I never deleted the question .. and it was an active question so I don't know why they would.  I posted a question in the EE Customer Service area and hopefully they can revive our discussion.

CJ
0
 
mbormannCommented:
I gave the URL in above post,
hoep it helps u.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now