I'm running into a very frustrating error on what was supposed to be a very simple script (I know java may not be the best for scripting, but here I am).
Anyway, I'm pulling names of printers from a csv file, and then I'm trying to create a folder named for each printer that I pulled from that csv file. The issue is that I can only write a directory for the printer if I type it in like this:
(new File("c:\\print\\printername").mkdir()
but if I do this:
String whatever = "c:\\print\\printername"
(new File(whatever)).mkdir()
no directory will be created. I'm baffled at what the problem might be. I've restructured my code a few times to try and track down the issue, and tried things like switching between mkdir() and mkdirs(), but still nothing. Here's my code
public static void main(String[] args) throws FileNotFoundException{
Scanner printers = new Scanner(new File("C:/Users/ransom/Desktop/printers.csv"));
printers.useDelimiter("\n");
String printerPath = "";
//new File("C:\\printer\\ISS114-Xerox4150PS").mkdir();
while(printers.hasNext()){
printerPath = "C:\\printer\\"+printers.next();
if(!(new File(printerPath)).mkdir()){
System.out.println(printerPath);
}
}
}
The line that is commented out is an example of when the script works, but if it gets to that line in the loop it doesn't create a directory. Any ideas?