import java.io.*;
class DirectoryTest
{
public static void main(
String[] a) throws IOException
{
File f=new File("dir1");
f.mkdir();
//directory created File f3=new File("directory1");
//only object created f3.mkdir();
//another directory created File f1=new File(f,"gud.txt");
File f2=new File(f,"first.txt");
f1.createNewFile();
//file gud.txt is created in dir1 f1.renameTo(f2);
/*another file first.txt is created with same data in
gud.txt..*/ f.renameTo(f3);
//rename the existing directory.... PrintWriter pw=new PrintWriter(f1);
pw.print("ganesh kumar");
pw.print(" cheekati:");
pw.flush();
pw.close();
}
}
renameTo method is used to create new file/directory with data which is same in the another directory.
if we take
f.renameTo(f3) dir1 has two files first.txt and gud.txt with data..
now it create new directory with name directory1 which has two files first and gud.txt with data.
In case of using renameTo in file i havenot mention createNewFile() method to create first.txt file.i just use f1.renameTo(f2); it create first.txt file with data.
but incase of directories if there is no f3.mkdir(); it is throwing FileNotFoundException.
why?
if i use it create directory1 dir with same two files like dir1 dir..
can anyone explain me?
[ November 08, 2008: Message edited by: Ganeshkumar cheekati ]