In my current project, I am writing code generator. The interface would be Command line.
In command line argument, user specifies specification files and destination folder, Which guides the code generator to generate files in specific destination folder.
For instance, my command line argument would be
VocArchSpec.text NetworkSpec.text ./src/fr/inria/arles/pankesh/gen ./src/fr/inria/arles/pankesh/gen/logic ./src/fr/inria/arles/pankesh/gen/sim/device ./src/fr/inria/arles/pankesh/gen/util
In the above command, 1 and 2 are specification and others are path of destination. This path is used by code generator. The code generator generates several java files in the specified destination folder.
But, my problem is I am getting following error :
java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
===============> I use following code to generate files.
new File(GlobalVariable.utilDirPath).mkdir(); // Assume that I set the value GlobalVariable.utilDirPath variable through command line arguments.
file = new File(GlobalVariable.utilDirPath + "/" + unit.getName());
file.createNewFile();
FileWriter writer = new FileWriter(file);
writer.write(content);
writer.flush();
Writer.close();
One way to get this exception is when the path (folder) where the file is to be created does not exist. Your code needs to make sure that the folders specified exist.
For an easy way to create these, look into File.mkdirs().