Reputation: 35
Hi I'm having a problem creating a folder in which every file I create in my for each loop will be placed. It is a basic problem but I can't seem to see it, any help would be much appreciated!
Scanner inputScan = new Scanner(System.in);
System.out.println("Enter location for output folder to be built..");
String filePath=inputScan.next();
inputScan.close();
File dir = new File(filePath+"subnet_output");
dir.mkdir();
for(String myAddr: addr){
String myFileName = myAddr.replaceAll("/", "-");
File file = new File(dir+myFileName+".txt");
PrintWriter writer = new PrintWriter(file, "UTF-8");
Upvotes: 1
Views: 64
Reputation: 340
You are missing "/" while creating file inside folder:
File file = new File(dir+myFileName+".txt");
Replace with:
File file = new File(dir+File.pathSeparator+myFileName+".txt");
Upvotes: 1
Reputation: 3164
Try PrintWriter.append(...)
and PrintWriter.flush()
for actually writing into that file you want to create.
Upvotes: 0