java - I am having trouble making a directory while iterating through a text file -
i new java , trying tie separate code, "making directory" , "reading text file". have far:
import java.io.*; public class filedir { public static void main(string[] args){ boolean dirflag = false; try { file myfile = new file("michael.txt"); file folder = new file("/users/chucknorr/desktop/"); filereader filereader = new filereader(myfile); bufferedreader reader = new bufferedreader (filereader); string line= null; while((line= reader.readline()) != null) { dirflag = folder.mkdir(line); } reader.close(); } catch(exception ex){ ex.printstacktrace(); } } }
i understand not correct, failed attempt tie code together. dirflag = folder.mkdir(line);
any appreciated, thanks!
there's no such method file#mkdir(string)
instead use...
file subfolder = new file(folder, line); if (!subfolder.mkdirs()) { // deal situations sub folder wasn't created }
for example.
take closer @ java.io.file
java docs
Comments
Post a Comment