简体   繁体   中英

Simultaneous read & write to file in Java

So my scenario is as follows:

I have a directory, and every X second a Java application polls the directory to see if any new files have been added. If a new file is detected (which may be transferred there by unknown FTP implementation), I want to have a look in the file to see if it ends with a specific string (ie "allData"). If the string exists, I will start to parse it for my needs since the file is considered to be successfully transferred.

So the problem is that the file being transferred may be really big (several GBs) and I don't want the parsing to start before the entire file has been completely transferred (which is indicated by the ending "allData" string). And when I want to have a look into the file for this string, the search has to be fast and low in memory consumption. Due to this reason I use a RandomAccessFile object (read only mode) which sets to file descriptor to quite near the end of the file, and then I start to search using that FD and a BufferedReader.

What my question is whether or not my file opening in the Java application will affect the file transfer being executed. Because it might be the case that the application starts to read (to decide whether or not the entire file has been transferred) before the file has been transferred. Will anything nasty happen in such an implementation?

我只是让远程端使用ftp传输文件,然后使远程端将文件从“filename.file.incomplete”重命名为“filename.file”,然后你可以查询那些没有“不完整”的东西。结束。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM