[转发]Creating a File Lock on a File Using Jdk1.4
来源:互联网 发布:欧陆风云4 mac 中文 编辑:程序博客网 时间:2024/05/29 05:57
The behavior of the file lock is platform-dependent. On some platforms, the file lock is advisory, which means that unless an application checks for a file lock, it will not be prevented from accessing the file. On other platforms, the file lock is mandatory, which means that a file lock prevents any application from accessing the file.
try { // Get a file channel for the file File file = new File("filename"); FileChannel channel = new RandomAccessFile(file, "rw").getChannel(); // Use the file channel to create a lock on the file. // This method blocks until it can retrieve the lock. FileLock lock = channel.lock(); // Try acquiring the lock without blocking. This method returns // null or throws an exception if the file is already locked. try { lock = channel.tryLock(); } catch (OverlappingFileLockException e) { // File is already locked in this thread or virtual machine } // Release the lock lock.release(); // Close the file channel.close(); } catch (Exception e) { }
- [转发]Creating a File Lock on a File Using Jdk1.4
- Creating and Using a Temporary File
- Creating a sequential file
- Creating a Root File System for Linux on OMAP35x
- Creating a XML Document from scratch without using a file in C#
- Creating a CAB file for your application
- Creating a File Manager in Adobe Air
- Re-creating a Password Authentication File
- Creating a document centric iPhone/iPad application with own file format using ZipArchive
- [mongoDB]exception in initAndListen: 20 Attempted to create a lock file on a read-only directory:
- Creating a Root File System for Linux on OMAP35x - 为Linux基于OMAP35x创建根文件系统
- File Locking Using a Cross-Platform API
- Truncate a file by using dd command
- C++ Read a whole File using ifstream
- Creating a custom server.xml file with Tomcat
- Creating a Data dictionary file to use with LogMi
- Using SOM to get a feature in a file
- Jinja2 example for generating a local file using a template
- 网页内容截取组件V1.0
- 孟宪会老师关于"将ASP纪录集输出成n列的的表格形式显示的方法"
- 激情在漫漫的消失
- request对象的用法
- SQL SERVER的数据类型
- [转发]Creating a File Lock on a File Using Jdk1.4
- 关于批处理命令!
- c#初学之petshop!
- 显示详细的ADO出错信息
- 让注册表记住VFP应用程序的使用次数
- 在VFP中调用API实现拨号上网
- Mysql
- flash工作流程设计
- 利用VFP在INTERNET上制作数据库动态查询