如何刷新'RandomAccessFile'(java)? [英] How do I flush a 'RandomAccessFile' (java)?
问题描述
我在java中使用RandomAccessFile:
I'm using RandomAccessFile in java:
file = new RandomAccessFile(filename, "rw");
...
file.writeBytes(...);
如何确保将此数据刷新到操作系统?没有file.flush()方法。 (请注意,我实际上并不期望它是物理写入的,我很满意它被刷新到操作系统,因此数据将在tomcat崩溃后继续存在,但不一定是意外的服务器断电)。
How can I ensure that this data is flushed to the Operating System? There is no file.flush() method. (Note that I don't actually expect it to be physically written, I'm content with it being flushed to the operating system, so that the data will survive a tomcat crash but not necessarily an unexpected server power loss).
我在Linux上使用tomcat6。
I'm using tomcat6 on Linux.
推荐答案
提供的唯一类a .flush()
方法是那些实际维护自己的缓冲区的方法。由于 java.io.RandomAccessFile
本身不维护缓冲区,因此不需要刷新它。
The only classes that provide a .flush()
method are those that actually maintain their own buffers. As java.io.RandomAccessFile
does not itself maintain a buffer, it does not need to be flushed.
这篇关于如何刷新'RandomAccessFile'(java)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!