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. Mysql的常见索引

    PRIMARY KEY(主键索引) ALTER TABLE table_name ADD PRIMARY KEY ( col ) 它是一种特殊的唯一索引,不允许有空值: UNIQUE(唯一索引) AL ...

  2. 有关ajax跨域问题

    写在前面 JQuery ajax支持get方式的跨域,采用了jsonp来完成.完成跨域请求的有两种方式实现.一种是使用Jquery ajax最底层的Api实现跨域的请求,而另一种则是JQuery aj ...

  3. MVC中根据后台绝对路径读取图片并显示在IMG中

    数据库存取图片并在MVC3中显示在View中 根据路径读取图片: byte[] img = System.IO.File.ReadAllBytes(@"d:\xxxx.jpg"); ...

  4. That IP address can't be assigned to.的问题

    That IP address can't be assigned to. 烦恼了很久,现在知道了,解决的办法如下 首先确定端口号是不是开放,阿里云的直接在控制台修改 其次 看看 你的地址是不是输入错 ...

  5. Python的virtualenv管理

    原文链接 虚拟环境 Python 开发中所谓的虚拟环境,就是为 Python 版本及第三方库创建独立的开发环境,使不同项目之间互不干扰.借助于虚拟环境,我们可以在同一台电脑上构建出项目 A 在基于 P ...

  6. php长连接应用

    php长连接和短连接 2012-12-05 17:25 3529人阅读 评论(0) 收藏 举报  分类: 我的收藏(8)  什么是长连接,如果你没听说过,可以往下看! 长连接到底有什么用?我想你应该见 ...

  7. JavaWeb 之 BeanUtils 工具类

    在上一个用户登录案例中,当从浏览器接收参数后,还需要创建 JavaBean 类,对其的属性每一项赋值,如果属性少,可以手动完成,但是当属性非常多,这时就发现非常不方便,在这里提供一个可以封装 Java ...

  8. POSIX多线程之创建线程pthread_create && 线程清理pthread_cleanup

    多线程之pthread_create创建线程 pthreads定义了一套C程序语言类型.函数.与常量.以pthread.h和一个线程库实现. 数据类型: pthread_t:线程句柄 pthread_ ...

  9. 查看zookeeper版本

    命令 echo stat|nc localhost 2181 zookeeper@kafka-zookeeper-0:/$ echo stat|nc localhost 2181 Zookeeper ...

  10. Give root password for maintenance

    linux开机出现"Give root password for maintenance (or type Control-D to continue):" 出现这种情况一般为两种 ...