English 中文(简体)
无法在按批号制作的档案中进行任何操作
原标题:Not able to perform any operation on a file created by batch
  • 时间:2012-05-04 14:05:29
  •  标签:
  • java

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.

请帮助我找到解决办法。 我整天浪费了我,试图看到解决办法:

问题回答

通过使用<代码>cmd /cstart > 启动批次文档,请按时间顺序重新开始,即:cmd.exe 正在创建第二程序以管理批次文档,proc.waitFor(>> >正在等待原始<代码>cmd.exe,但不适用于批次文档本身。 然后,批量档案与 Java方案平行运行,在档案建立之前,试图从 Java改档案。

相反,仅使用<条码>cmd /c batch.bat,这应处以罚款。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签