开发者

How to compute file size, which is already opened and being read by another thread using JAVA

I want to compute the size of the file which is already opened and being written by another thread usin开发者_JAVA技巧g JAVA.


You can use FileChannel of the Java API's.

A channel for reading, writing, mapping, and manipulating a file.

File channels are safe for use by multiple concurrent threads. The close method may be invoked at any time, as specified by the Channel interface. Only one operation that involves the channel's position or can change its file's size may be in progress at any given time; attempts to initiate a second such operation while the first is still in progress will block until the first operation completes


If you want to know the size of a file use File.length(). Who is writing to the file doesn't matter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜