开发者

Removing file locks in Windows and Java

开发者 https://www.devze.com 2022-12-25 03:14 出处:网络
I have a Java program that opens a file using the RandomAccessFile class. I\'d like to be able to rename that file while it is opened by Java. In Unix, this isn\'t a problem. Does anyone know how I c

I have a Java program that opens a file using the RandomAccessFile class.

I'd like to be able to rename that file while it is opened by Java. In Unix, this isn't a problem. Does anyone know how I can do thi开发者_开发技巧s in Windows?

Should I set Java to open it a certain way?

Thanks in advance.

Edit, clarification: I'd like to be able to set this file sharing access in my Java code.


You need to close any handles on the file at any way. E.g. a FileOutputStream on that File must be closed before you can rename it. That's just the way how the Windows file system works.


in_stream.close();            
out_stream.getChannel().close();
out_stream.close();

Anyhow in Windows it stay locked :*(

0

精彩评论

暂无评论...
验证码 换一张
取 消