Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

renameTo()

 
Tex Abrey
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Thanks
Tex
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me the documentation in the JavaDocs for java.io.File is pretty clear. In a server situation you may run into security restrictions that prevent arbitrary renameTo.
What exactly have you tried?
Bill
 
Tex Abrey
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code I am using
<%-- java include files --%>
<%@ page import="java.io.*" %>
<%@ 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);
out.println(moved);

try{
boolean flag = false;
flag = old.renameTo(moved);
out.println(flag);
}
catch(Exception e) {
System.out.println(e);
}
}
%>
 
Tex Abrey
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic