Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concurrent read/write file in Java

I have to read a text file from my Java application.

The file contains many rows and this file is updated every X minutes from an external unknown application that appends new lines to the file.

I have to read all the rows from the file and then I have to delete all the records that I've just read.

Is it possibile to let me read the file row by row, deleting each row I read and at the same time allowing the external application to append other rows to the file?

This file is located in a Samba shared folder so I'm using jCIFS to read/write the file and BufferedReader Java class.

thanks in advance

like image 307
Roberto Milani Avatar asked Aug 04 '16 15:08

Roberto Milani


1 Answers

I don't know the perfect solution to your problem, but I would solve it differently:

  • rename the file (give it a unique name with an timestamp)
  • the appender job will then automatically re-create it
  • process your time-stamped files (no need to delete them, keep them in place so you can later check what happened)
like image 139
Sean Patrick Floyd Avatar answered Oct 03 '22 23:10

Sean Patrick Floyd