java - Why does this code recreate the same file every time it is run? -


i trying create file named virtualatm.txt in given directory if not exist, if exist shouldn't file , continue. finding code, whether file exists or not, wiping data inside file , re-creating every time run it. code used below:

try{         string dirtowritefile = system.getproperty("user.dir") + "/virtualatm.txt"; //get path write text file to.         dirtowritefile.trim();         file file = new file(dirtowritefile);         if (!file.exists()) {             file.createnewfile(); }catch(ioexception e){     e.printstacktrace(); } 

can tell me why happens?

here

if (!file.exists() && file.isdirectory()) 

you checking if file exits , should not directory. no need if want check if file exists

just use

if (!file.exists) 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -