在读取文件之前检查文件是否打开? [英] Check if a file is open before reading it?

查看:30
本文介绍了在读取文件之前检查文件是否打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个小程序,它以非常频繁的时间间隔(每秒几次)读取本地文件系统(用户计算机)上的文件,然后通过以下方式将文件的内容提供给网页javascript.

I'm trying to make an applet that reads a file on the local file system (the users computer) at a very frequent interval (several times a second), then makes the contents of the file available to the web page via javascript.

小程序需要读取的文件由用户计算机上的程序进行高频更新.我担心的是,如果小程序在文件更新过程中从文件中读取数据,可能会发生什么.

The file the applet needs to read is updated at a high frequency by a program on the user's computer. What I'm concerned about is what might happen if the applet reads data from the file when the file is in the middle of being updated.

我不知道这种可能性有多大,但如果这是一个有效的问题,有没有办法在读取文件之前确保当前没有写入文件?

I don't know how likely this is, but if it is a valid concern is there a way to make sure the file is not currently being written to before reading it?

推荐答案

我对此并不乐观,但你可以试试 java.io.FileInputStream,或该包中的其他一些选项.

I'm not positive about this, but you could try java.io.FileInputStream, or some other option from that package.

另外,这个问题可能是重复的.这可能会回答您的问题:

Also, this question may be a duplicate. This might answer your question:

  1. 如何使用 Java 从正在写入的文件中读取数据?
  2. 在写入文件时读取文件
  3. 在写入文件时读取文件
  4. 从文件中读取数据正在写入

这篇关于在读取文件之前检查文件是否打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆