The code below describes a Java situation. I used some psudocode in the getRuntime().exec function; but, the main point is that a new file is created.
Although the second line causes an error the first time it is run I can see the new file has been created. Also, the 2nd time I run it, it works; I mean to say the 2nd time it is run, it can read the file created on the previous run. So, the best I can figure is that the 2nd line needs to wait until the new file is created (~1,000 lines of text).
Runtime.getRuntime().exec(new String[] {"Do something that writes a new file", "c:/"+newFileName+".xml"});
...
File fileToParse = new File("c:/"+newFileName+".xml");
Creating files can be done natively in Java using the
File.createNewFile()method. That is much nicer and clearer.Since you told us that you use a utility which doesn’t simply create a file but also write data to it, this doesn’t answer the question, of course.
In addition to JB Nizet’s answer, I want to tell that I had some problems with the
waitFor()method. It didn’t want to return. I guess it was because of I didn’t read all the output of the process (bystdout). What do others think about this? Is this a relevant conclusion? I just read the first couple of lines of the output and calledwaitFor(), but there was still a lot of other output after those couple of lines.