I have written a small application to archive historical data from a set of weather station. My program does the following:
我写了一个小应用程序来存档来自一组气象站的历史数据。我的程序执行以下操作:
- Check if input file exists
- Check if input file is open by another program (probably, the application sending data from the weather stations).
- Append all the contents to an archive file.
- Delete the input file (will be created again next time there is new data from the weather stations).
检查输入文件是否存在
检查输入文件是否由另一个程序打开(可能是应用程序从气象站发送数据)。
将所有内容附加到存档文件。
删除输入文件(下次有气象站的新数据时将再次创建)。
The Java program is running on a Windows machine, and if accessing a local file everything runs smoothly (I can check whether the file exists and whether it is in use). But when we started using a Linux drive mapped onto the Windows machine, I started getting false negatives on the exists-check and false-positives on the in-use-check.
Java程序在Windows机器上运行,如果访问本地文件,一切运行顺畅(我可以检查文件是否存在以及是否正在使用)。但是,当我们开始使用映射到Windows机器上的Linux驱动器时,我开始对使用中检查中的存在检查和误报进行错误否定。
Any ideas on what I can do to make it work?
关于我能做些什么才能让它发挥作用的任何想法?
Here is my code:
这是我的代码:
File originalFile = new File (currentPath + "\\" + line[1]);
if (originalFile.exists()) {
boolean fileIsNotLocked = originalFile.renameTo(originalFile);
if (fileIsNotLocked) {
/* WORK WITH THE FILE TO COPY ITS CONTENTS ETC */
if(originalFile.delete())
System.out.println("Successfully deleted file at = " + originalFile);
else
System.out.println("Could not delete file at = " + originalFile);
}
}
1 个解决方案
#1
0
For the record, the solution was using the JCIFS library: https://jcifs.samba.org/
为了记录,解决方案是使用JCIFS库:https://jcifs.samba.org/
#1
0
For the record, the solution was using the JCIFS library: https://jcifs.samba.org/
为了记录,解决方案是使用JCIFS库:https://jcifs.samba.org/