import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileLock; public class FileLockTest {
public static void main(String[] args) {
try (
var channel = new FileOutputStream("a.txt").getChannel())
{
FileLock flock = channel.lock();
Thread.sleep();
flock.release();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

learning java 文件锁的更多相关文章

  1. Learning Java language Fundamentals

    Chapter 2 Learning Java language fundamentals exercises: 1.What  is Unicode? Unicode is a computing ...

  2. blogs for learning java

    曹海成的专栏 http://blog.csdn.net/caohaicheng/article/details/38071097 http://blog.csdn.net/a5489888/artic ...

  3. Learning Java IO indexes

    I/O Streams, it simplifies I/O operations, write a whole object out to stream & read back. File ...

  4. Learning Java 8 Syntax (Java in a Nutshell 6th)

    Java is using Unicode set Java is case sensitive Comments, C/C++ style abstract, const, final, int, ...

  5. Learning Java characteristics (Java in a Nutshell 6th)

    Java characteristics: Java .class files are machine-independent, including the endianness. Java .cla ...

  6. [Java in NetBeans] Lesson 00. Getting Set-up for Learning Java

    这个课程的参考视频在youtube. 主要学到的知识点有: set up needs Java SE JDK, NetBeans IDE class name should be the same l ...

  7. learning java 使用WatchService监控文件变化

    import java.io.IOException; import java.nio.file.*; public class WatchServiceTest { public static vo ...

  8. learning java FileVisitor 遍丽文件及路径

    import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttribut ...

  9. learning java Paths Path

    import java.nio.file.Path; import java.nio.file.Paths; public class PathTest { public static void ma ...

随机推荐

  1. 【C语言】崩溃的双重指针

    指针的指针? 前言: 指针的初识点击移步 双重指针: 指向指针的指针是一种多级间接寻址的形式,或者说是一个指针链.通常,一个指针包含一个变量的地址.当我们定义一个指向指针的指针时,第一个指针包含了第二 ...

  2. CLRS10.1-7练习 - 用双队列实现栈

    算法中心思想: 始终向非空队列进行入队操作 初始化时两个队列都为空,我们对q1进行入队操作 入栈: 只需执行其中一个队列入队操作即可, 具体操作哪一个队列,用一个标记变量标记 出栈流程图 代码实现 p ...

  3. robotframework_酷我音乐_That Girl

    *** Settings *** Library Selenium2Library *** Test Cases *** music # 打开浏览器 Open Browser https://www. ...

  4. mysql 导入sql大文件

    引自:https://dba.stackexchange.com/questions/83125/mysql-any-way-to-import-a-huge-32-gb-sql-dump-faste ...

  5. JVM与并发

    1.jvm内存模型 硬件内存模型 处理器-->高速缓存-->缓存一致性协议-->主存 java内存模型 线程<-->工作内存<-->save和load < ...

  6. 多次执行echarts时出现 there is a chart instance already initialized on the dom

    原因,多次使用 echarts.init(document.getElementById(this.options.zid)); 解决方案 设为全局

  7. dataGridView读写文本

    constant con = new constant(); private void loadlistbox2() { dataGridView1.ColumnCount = 1; string z ...

  8. SQL Server 隔离级别(RC&RR)

  9. 如何使用Git 优雅的版本回退呢?

    在版本迭代开发过程中,相信很多人都会有过错误提交的时候(至少良许有过几次这样的体验).这种情况下,菜鸟程序员可能就会虎驱一震,紧张得不知所措.而资深程序员就会微微一笑,摸一摸锃亮的脑门,然后默默的进行 ...

  10. pychrom注册码

    http://angame.top/wx/web/zhucema/ YZVR7WDLV8-eyJsaWNlbnNlSWQiOiJZWlZSN1dETFY4IiwibGljZW5zZWVOYW1lIjo ...