In that
index.delete(); if (!index.exists()) { index.mkdir(); }
you call
if (!index.exists()) { index.mkdir(); }
after
index.delete();
This means that you create the file again after deletion. File.delete () returns a boolean value. Therefore, if you want to check, then do System.out.println(index.delete()); if you get true then it means this file is deleted
File index = new File("/home/Work/Indexer1"); if (!index.exists()) { index.mkdir(); } else{ System.out.println(index.delete());
from the comments below, the updated answer is as follows
File f=new File("full_path");//full path like c:/home/ri if(f.exists()) { f.delete(); } else { try { //f.createNewFile();//this will create a file f.mkdir();//this create a folder } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
SpringLearner Nov 29 '13 at 9:09 2013-11-29 09:09
source share