0

I have problem with file.I have application 1 and application 2 , application 1 create file (have process time). I want use from created file in application 2 when the process application 1 end. I use polling check for created file but can't understand file was closed or not(process application 1 end). Source application 1 locked and I want change source application 2.

Morteza Jalambadani
  • 2,190
  • 6
  • 21
  • 35

2 Answers2

2

Since you don't have access to the app 1. The only thing we can do is from app 2.

If you are on a Windows system, the system will not allow you to change the file name if other process is reading/writing the file.

You can try to rename the output file from app 2. If it works fine, then the file wasn't opened by other process and you can start processing the output file. Of course you may wish change the file name back.

renameTo Java Doc

Please note, *NIX systems will have different behavior

Yang
  • 858
  • 6
  • 22
0

You could use a temporary name for the file and then rename it to the proper name once it has been fully written.

You could create a ".lock" file to signal that it is locked for read or write. Once the reading or writing is complete you can delete the lock file. Each application should only read or write the file if the lock file is not present (and should create the lock file before performing its read or write operation and delete it as soon as it has finished).

ᴇʟᴇvᴀтᴇ
  • 12,285
  • 4
  • 43
  • 66