I am fixing a bug in a Java class that is given by another developer. The problem happens in this line of code:
The error message is:
.\output\gov.nih.nci.cabio.domain._test.xml (The system cannot find the path specified)
Question 1: should I create a directory called "output"?
Question 2: where should I create this "output" directory?
Question 3: should I also create an empty file with a name "gov.nih.nci.cabio.domain._test.xml"?
2. If you want to use that code, you should create it under the current working directory which was and will be in effect when that code is run.
3. No, you don't need to create an empty file before writing. The FileWriter or FileOutputStream will take care of that.
And for the question you didn't ask yet:
4. What happens if I can't control the current working directory which will be in effect when that code is run?
In that case you should choose a fixed location for the "output" directory and write your code so that it refers to that fixed location. Use an absolute path instead of a relative path.