By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,653 Members | 1,483 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,653 IT Pros & Developers. It's quick & easy.

file upload in jsp

P: 2
I have to upload a file using jsp. Am using netbeans 6.9. The file gets uploaded successfully if the source file name & destination file name are same. But in my application I have to change the destination file name for which I used the following code:
"sourceFileName.renameTo(destinationFileName); "
But then the function renameTo() is not regonised by the IDE in spite of me importing java.lang.*
Please help.
Thanks in advance.
Mar 1 '12 #1
Share this Question
Share on Google+
3 Replies


10K+
P: 13,264
renameTo is a method in the File class not in the String class.
Call it on a File handle that represent your file.
Mar 1 '12 #2

P: 2
Sorry.. I din't get you..
I have used it in the try block of my jsp. If i don't rename my source file, it is getting uploaded successfully...
Mar 1 '12 #3

10K+
P: 13,264
Don't do sourceFileName.renameTo(destinationFileName)

Instead do
Expand|Select|Wrap|Line Numbers
  1. new File(sourceFileName).renameTo(destinationFileName);
if it's allowed on your system.
P.S You should not be writing Java code in JSPs
Mar 1 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.