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

renaming file

How do I rename a file using Java?  An example would be appreciated.  I tried using File.renameTo(), but I can't seem to get it to work.  I'm using jdk 1.1.7
0
danGynn
Asked:
danGynn
1 Solution
 
imladrisCommented:
Yup, renameTo is the thing to use. It would go something like this:

File of=new File("test");
File nf=new File("ntest");
of.renameTo(nf);


This will cause a file named test to be renamed to ntest. If you still have trouble, try using a complete path (like "c:\\myprog\\test") and/or post your code. (The double backslashes are needed because a backslash is an escape character in Java).
0
 
danGynnAuthor Commented:
I realized what I was doing wrong. I'm using COS for servlets and didn't get the upload filename correctly.  Thanks for you help though.
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.

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