문제

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 this 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 :*(

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top