try this good luck to you! :)import java.io.*; import java.lang.*;public class helloWorld { File directory; public helloWorld() { System.out.println("this is the hello world test for make directory and delete it"); } public void createDir(String dir) { if(dir==null) { directory = new File("d:/newDir/new/temp"); } else { directory = new File(dir); } /** create new Directory: * create new file then use: directory.createNewFile(dir); * for example: (delete the file d:/cccc/1.txt) * directory=new File("d:/cccc","1.txt"); * directory.delete(); */ boolean flagCreate=directory.mkdirs(); System.out.print("Create Directory: "+ directory.toString() +"--------\n" + flagCreate+"\n"); } public void deleteDir(String dir) { if(dir==null) { directory = new File("d:/newDir/new/temp"); } else { directory = new File(dir); } if (directory.exists()&& directory.listFiles().length ==0) { /* delete the directory if it is blank in this example it only del the directory "d:\ccccc\a"but the "d:/ccccc" still exist */ boolean flagDelete=directory.delete() ; System.out.print("Delete Directory: "+ directory.toString() +"--------\n" +flagDelete +"\n"); } } public static void main(String args[]) { helloWorld tt=new helloWorld(); tt.createDir("d:/ccccc/a"); tt.deleteDir("d:/ccccc/a"); } }
/*
create tmp file
*/public class tmp
{
public static void main(String args[])
{
try
{
File fff=new File(".");
fff=null; //now directory
File tmpfile=File.createTempFile("tmp",".tmp",fff);//create tmp file
FileOutputStream fout=new FileOutputStream(tmpfile);
PrintStream out=new PrintStream(fout);
out.println("aaaaaaaaaaaaaaaaaaaaaaaa");//write to tmp file
tmpfile.deleteOnExit();//del tmp file
System.out.println("exit");
System.exit(0);
}
catch(IOException ii)
{
System.out.println("can not create tmp file !");
}
catch(IllegalArgumentException eee)
{
System.out.println("ERROR");
}
catch(SecurityException ee)
{
System.out.println("ERROR");
}
}
}
good luck to you!
:)import java.io.*;
import java.lang.*;public class helloWorld { File directory; public helloWorld() {
System.out.println("this is the hello world test for make directory and delete it");
}
public void createDir(String dir) {
if(dir==null) {
directory = new File("d:/newDir/new/temp");
}
else {
directory = new File(dir);
} /** create new Directory:
* create new file then use: directory.createNewFile(dir);
* for example: (delete the file d:/cccc/1.txt)
* directory=new File("d:/cccc","1.txt");
* directory.delete();
*/
boolean flagCreate=directory.mkdirs(); System.out.print("Create Directory: "+ directory.toString() +"--------\n" + flagCreate+"\n"); }
public void deleteDir(String dir) {
if(dir==null) {
directory = new File("d:/newDir/new/temp");
}
else {
directory = new File(dir);
}
if (directory.exists()&& directory.listFiles().length ==0) {
/* delete the directory if it is blank
in this example it only del the directory "d:\ccccc\a"but the "d:/ccccc" still exist */
boolean flagDelete=directory.delete() ;
System.out.print("Delete Directory: "+ directory.toString() +"--------\n" +flagDelete +"\n"); } }
public static void main(String args[]) {
helloWorld tt=new helloWorld();
tt.createDir("d:/ccccc/a");
tt.deleteDir("d:/ccccc/a");
}
}