This is what I am trying to achieve: Run a batch file from a JAVA program. The batch creates a new file in a specific folder, let s say folder A . Once the new file is created, JAVA program moves the newly created file from folder A to folder B .
如下:
// Run a batch that creates a file
String[] cmd = new String[]{"cmd", "/C", "start /min" + batchFilePath + batchFileName};
Process proc = Runtime.getRuntime().exec(cmd);
proc.waitFor();
// Command in the batch file
dir c: > C:Chen_MedEDICronEDIOUT est.edi
exit
// Move the file created by batch
boolean result2= ediOutFile.renameTo(new File(processedFolder, ediOutFile.getName()));
This is what happens when I run the above code: New file gets created in folder A . However, the newly created file is not moved to folder B .
Analysis:
There is no syntactical issue in above code. I tried an alternative to moving the file. That is, read-write the file from folder A to folder B and then deleting the file from folder A . New file is created in folder B , however, file is not deleted from folder B . When I run another program that tries to move the file, after above program is executed, it works. That said, there seems to be an issue with Runtime holding the control over the file.
请帮助我找到解决办法。 我整天浪费了我,试图看到解决办法: