我无意中在 Linux 上运行了一个 Java 程序,它所在的分区、它的属性和日志所在的分区接近 100% 满。它失败了,但是在解决了磁盘空间的问题后,我再次运行它并且第二次失败了,因为它的属性文件是 0 字节长。
我没有文件的来源,我不想反编译类文件,但我想知道属性的损坏是否可能是因为程序未能写入属性文件.
神秘之处在于,我希望这些属性是只读的,并且不会记忆起程序正在更新的任何项目。难道即使只读了属性,文件也是以读写方式打开的,分区满了就可能消失?
注意该程序在过去几年中至少运行了 1000 次而没有出现故障或事故。
最佳答案
I don't have source of the file and I don't want to go as far as decompiling the class files, but I was wondering whether the corruption of the properites could be because the program failed to write to the properties file.
这是最有可能的解释。本来会有异常,但应用程序可能已将其压缩……或者您可能没有注意到错误消息。 (事实上 ,如果应用程序试图将错误记录到文件中,那很可能也会失败。)
Could it be that even if the properties are only read, the file is opened in read-write mode and could disappear if the partition is full?
在这种情况下,这不太可能是答案。与许多语言不同,在 Java 中,读取文件和写入文件的代码涉及不同的流类。很难想象应用程序的开发人员如何/为什么会打开属性文件进行写入(截断),如果从来没有任何意图写入它的话。
最合理的解释是应用程序确实更新了属性文件。 (尝试再次安装程序,使用它,停止它,并查看属性文件的修改时间戳。)
N.b. this program has run without failure or incident at least 1000 times over several years.
我敢打赌这是您第一次在磁盘已满时运行它:-)
关于Linux 上低磁盘空间条件下的 Java 属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9593301/