我打开了一个文件,然后我锁定了一个文件区域,我希望更新一个值,然后将其重写回文件。我在尝试写入已锁定的文件时收到以下错误消息:
// Now lets get a lock on the first 10 characters
try( RandomAccessFile raFile = new RandomAccessFile( cbooking, "rw" );
FileChannel channel = raFile.getChannel();
FileLock lock = channel.lock( 1 , 10, true) ) {
// Write the new value to the file
byte[] bytes = " ".getBytes();
raFile.write( bytes );
}
catch ( IOException e) {
e.printStackTrace();
// TODO Add logging - Could not gain character lock on the file!
return false;
}
代码示例:
<div class="mySlides">
<div class="numbertext">1 / 4</div>
<img src="http://chasingseals.com/wp-content/uploads/2014/02/greenlandBanner2000x800.jpg" class="img">
</div>
...
</div>
.img {
max-width:100%;
max-height:100%;
width: auto;
height: auto;
object-fit: scale-down;
}
任何意见都赞赏。
答案 0 :(得分:0)
如果您认为它确实没有被其他实例锁定,请尝试FileChannel.open而不是通过RandomAccessFile获取频道