File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes renameTo() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "renameTo()" Watch "renameTo()" New topic


Tex Abrey

Joined: Oct 04, 2002
Posts: 24
Does anyone have an example as to how to use the renameTo() I can't find a good example that explains at all whats going on, on the net I want to move a file from one directory to another
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Seems to me the documentation in the JavaDocs for is pretty clear. In a server situation you may run into security restrictions that prevent arbitrary renameTo.
What exactly have you tried?
Tex Abrey

Joined: Oct 04, 2002
Posts: 24
This is the code I am using
<%-- java include files --%>
<%@ page import="*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.lang.Object" %>
<%@ page import="java.lang.System" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.StringTokenizer" %>
//local directories
String dirURL= "/inet/docroot/Newsclippings/upload/.";
String absDIR= "/inet/docroot/Newsclippings/clippings/";
//collecting information from the clipping directory given above
File path = new File(dirURL);
//array for clipping directory contents
String[] list = path.list();
//starts going through the list of pdf files, searching for those that match the search criteria
for(int i = 0; i < list.length; i++) {
String pdfName = list[list.length - 1 - i];
String year = pdfName.substring(0,2) + "/";
String mon = pdfName.substring(3,5) + "/";
File old = new File(dirURL + pdfName);
File moved = new File(absDIR + year + mon + pdfName);

boolean flag = false;
flag = old.renameTo(moved);
catch(Exception e) {
Tex Abrey

Joined: Oct 04, 2002
Posts: 24
This is the out put i get
/inet/docroot/dabrey/Newsclippings/clippings/02/01/02-01-11_R01.pdf false
and the folder i am moving the file to has read/write/execute abilities
I agree. Here's the link:
subject: renameTo()
It's not a secret anymore!