On 12/11/2012 23:22, Jim Gish wrote:
Which file(s) are you concerned about truncating/damaging? The code
I'm impacting is for creating a new lock file. Where is the potential
for truncating/damaging that you both are referring to?
Is this sufficient (plus the proper exception handling of course) ?
//lockStream = new FileOutputStream(lockFileName);
fc = FileChannel.open(new
File(lockFileName).toPath(), CREATE_NEW, WRITE);
//fc = lockStream.getChannel();
CREATE rather than CREATE_NEW so that it doesn't fail if the lock file
already exists. Although it's just a lock file then I think it would be
impolite to truncate it.
You could use Paths.get(lockFileName)rather than new
File(lockFileName).toPath() here but either is fine.
-Alan.