I want to move file from one folder to other. I am using File#renameTo() method, but file is not renamed. I am not getting what is going wrong.
I am using Netbeans 7.0.1 and Apache Tomcat.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m assuming that you are trying to move files around in a web application.
Remember : servlets running in containers are restricted in terms of where they can read/write files – this is a security measure that is configurable .
You have several options :
1) Use a simpler servlet container like Jetty (the security defaults in Jetty are less restrictive).
2) Update the catalina policies file : Setting catalina.policy to allow file access by servlets
3) Be more careful about where your trying to move files to. The servlet API has “getResource…” hooks which reference you to the servlets “home” environment.
You might also take this as a precaution : I find that when I’m moving things around at the file level in a servlet, its usually due to a shortcut which is unnecessary (take a good look at existing Java EE APIs, are you sure that the functionality youre getting out of all this File I/O isn’t already provided …?) …