java - While traversing through a directory if a subdirectory is identified how to create an empty file within it.? -


code: - lists files checks if file subdirectory or not , prints . within if clause must embed code using createnewfile() new file created in subdirectories. how do it?

file directory = new file(directoryname);                               //get files directory                 file[] flist = directory.listfiles();                    (file file : flist){                             if (file.isfile()){                                      system.out.println("files: " + file.getname());                              } else if (file.isdirectory()){                  file.createnewfile();             system.out.println("subdirectory :" +file.getname());             }                    }            }  

you need give new name new file want create:

else if (file.isdirectory()){             file nf = new file(file.getabsolutepath()+file.separator+"newfile")                  nf.createnewfile();             system.out.println("subdirectory :" +file.getname());             } 

something this.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -