Below is the code I am using to rename a file. I am running IIS 4.0 and JRun Server. The permissions on the directory are set to write by the web server account and the file to be copied is not an archive file. These are the only things I can think of that would prevent this code from working.
String s=("input.txt");
String d=("copy.txt");
File f1 = new File(s);
File f2 = new File(d);
boolean b;
b=f1.renameTo(f2);
if (b)
out.println("Sucessfully Transfered!");
else
out.println("Not Transfered!");
Thanks
-
File rename in jsp (11 messages)
- Posted by: Nancy Anderson
- Posted on: April 17 2001 10:23 EDT
Threaded Messages (11)
- File rename in jsp by Nicky Eshkenazi on April 17 2001 11:24 EDT
- File rename in jsp by Nancy Anderson on April 17 2001 14:32 EDT
-
File rename in jsp by Nicky Eshkenazi on April 17 2001 04:05 EDT
-
File rename in jsp by Nancy Anderson on April 17 2001 04:34 EDT
-
File rename in jsp by Nicky Eshkenazi on April 17 2001 05:04 EDT
-
File rename in jsp by Nancy Anderson on April 18 2001 09:04 EDT
-
File rename in jsp by Nancy Anderson on April 18 2001 09:11 EDT
-
File rename in jsp by Nicky Eshkenazi on April 18 2001 09:52 EDT
-
File rename in jsp by Nancy Anderson on April 18 2001 10:11 EDT
- File rename in jsp by Nancy Anderson on April 18 2001 10:31 EDT
- File rename in jsp by Nicky Eshkenazi on April 18 2001 10:43 EDT
-
File rename in jsp by Nancy Anderson on April 18 2001 10:11 EDT
-
File rename in jsp by Nicky Eshkenazi on April 18 2001 09:52 EDT
-
File rename in jsp by Nancy Anderson on April 18 2001 09:11 EDT
-
File rename in jsp by Nancy Anderson on April 18 2001 09:04 EDT
-
File rename in jsp by Nicky Eshkenazi on April 17 2001 05:04 EDT
-
File rename in jsp by Nancy Anderson on April 17 2001 04:34 EDT
-
File rename in jsp by Nicky Eshkenazi on April 17 2001 04:05 EDT
- File rename in jsp by Nancy Anderson on April 17 2001 14:32 EDT
-
File rename in jsp[ Go to top ]
- Posted by: Nicky Eshkenazi
- Posted on: April 17 2001 11:24 EDT
- in response to Nancy Anderson
Nancy,
have you tried to put the .renameTo(File dest) method in a try {} block and catch any exceptions:
1. SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.io.FileDescriptor) method denies write access to both the old and new pathnames
2. NullPointerException - If the parameter dest is null
Nicky
-
File rename in jsp[ Go to top ]
- Posted by: Nancy Anderson
- Posted on: April 17 2001 14:32 EDT
- in response to Nicky Eshkenazi
I don't think I know how to properly utilize the catch feature. I've added the try and catch blocks, but I'm not sure where the errors are going. Thanks for your help. -
File rename in jsp[ Go to top ]
- Posted by: Nicky Eshkenazi
- Posted on: April 17 2001 16:05 EDT
- in response to Nancy Anderson
The try {} catch() will actually serve what you trying to accomplish with the if statement, but it will be better and will provide with more info on what exactly is taking place. The boolean value will give you only:
- true - in case of succesful renaming;
- false - unsuccesful;
if you do:
try {
boolean b;
b=f1.renameTo(f2);
} catch (SecurityException se) {
System.out.println("SecurityException")
ex.printStackTrace ();
} catch (NullPointerException npe) {
System.out.println("NullPointerException")
npe.printStackTrace ();
}
this will give you a good idea of what is taking place, if an Exception isn't thrown then you know that it is working fine and you need to look for the problem in another place - paths, permissions and etc.. -
File rename in jsp[ Go to top ]
- Posted by: Nancy Anderson
- Posted on: April 17 2001 16:34 EDT
- in response to Nicky Eshkenazi
Ok. thanks. No exception was thrown.
The directory is writable by the web server anonymous account. The input file is not an archive file. the jsp page is in the same directory as the file to be renamed. I just call the file name, not the path since they are in the same directory.
-
File rename in jsp[ Go to top ]
- Posted by: Nicky Eshkenazi
- Posted on: April 17 2001 17:04 EDT
- in response to Nancy Anderson
what is the error, if any that you are getting after compilation? I just tried your code in my environment and works fine.
-
File rename in jsp[ Go to top ]
- Posted by: Nancy Anderson
- Posted on: April 18 2001 09:04 EDT
- in response to Nicky Eshkenazi
I get no errors when I compile the jsp file. -
File rename in jsp[ Go to top ]
- Posted by: Nancy Anderson
- Posted on: April 18 2001 09:11 EDT
- in response to Nancy Anderson
I've gone back and added the full path to the file in case that was the problem, but that did not fix it. -
File rename in jsp[ Go to top ]
- Posted by: Nicky Eshkenazi
- Posted on: April 18 2001 09:52 EDT
- in response to Nancy Anderson
Nancy,
would you post the whole JSP file, so I could look at it?
Nicky -
File rename in jsp[ Go to top ]
- Posted by: Nancy Anderson
- Posted on: April 18 2001 10:11 EDT
- in response to Nicky Eshkenazi
<%@ page import="java.io.*" %>
<html>
<body>
<%
try {
String s=("d:\\\\production\\\\f2jsite\\\\test\\\\fileread
testfileio.jsp");
out.println(s);
out.println("<br>");
String d=("d:\\\\production\\\\f2jsite\\\\test\\\\fileread
copy.txt");
out.println(d);
out.println("<br>");
File f1 = new File(s);
boolean read;
read = f1.canRead();
out.println(read);
out.println("<br>");
boolean write;
write = f1.canWrite();
out.println(write);
out.println("<br>");
File f2 = new File(d);
boolean read2;
String path;
read2 = f2.canRead();
path = f1.getAbsolutePath();
out.println(read2);
out.println("<br>");
out.println(path);
out.println("<br>");
boolean write2;
write2 = f2.canWrite();
String path2;
path2 = f2.getAbsolutePath();
out.println(write2);
out.println("<br>");
out.println(path2);
out.println("<br>");
boolean b;
b=f1.renameTo(f2);
if (b)
out.println("transferred");
else
out.println("arrrggggghhhhh");
}
catch (SecurityException se) {
out.println("SecurityException");
se.printStackTrace ();
}
catch (NullPointerException npe) {
out.println("NullPointerException");
npe.printStackTrace ();
}
%>
</body>
</html>
here's the output I get (http://www.fruit2juice.com/test/fileread/testcopy.jsp)
d:\\production\\f2jsite\\test\\fileread\testfileio.jsp
d:\\production\\f2jsite\\test\\fileread\copy.txt
false
false
false
d:\production\f2jsite\test\fileread\testfileio.jsp
false
d:\production\f2jsite\test\fileread\copy.txt
arrrggggghhhhh -
File rename in jsp[ Go to top ]
- Posted by: Nancy Anderson
- Posted on: April 18 2001 10:31 EDT
- in response to Nancy Anderson
mmm. I got it working. It would appear that I did not have the file path correct. I appreciate all your help. I feel not so bright at the moment. But, I learned a fair amount about debugging. So, again, thanks.
-
File rename in jsp[ Go to top ]
- Posted by: Nicky Eshkenazi
- Posted on: April 18 2001 10:43 EDT
- in response to Nancy Anderson
What is the OS on the production server? Win or Unix?