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
Post a Comment