java File 判断文件是否为符号链接
来源:互联网 发布:windows文件系统结构 编辑:程序博客网 时间:2024/05/16 00:24
转自:http://blog.csdn.net/a1129963143/article/details/9255449
最简单的方式,直接使用:
- private static boolean isSymbolicLink(File f) throws IOException {
- return !f.getAbsolutePath().equals(f.getCanonicalPath());
- }
如果是普通文件,file.getAbsolutePath()和file.getCanonicalPath()是一样的。
如果是link文件,file.getAbsolutePath()是链接文件的路径;file.getCanonicalPath是实际文件的路径(所指向的文件路径)。
apache 使用的判断方式:
The technique used in Apache Commons uses the canonical path to the parent directory, not the file itself. I don't think that you can guarantee that a mismatch is due to a symbolic link, but it's a good indication that the file needs special treatment.
- public static boolean isSymlink(File file) throws IOException {
- if (file == null)
- throw new NullPointerException("File must not be null");
- File canon;
- if (file.getParent() == null) {
- canon = file;
- } else {
- File canonDir = file.getParentFile().getCanonicalFile();
- canon = new File(canonDir, file.getName());
- }
- return !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
- }
0 0
- java File 判断文件是否为符号链接
- java File 判断文件是否为符号链接
- java File 判断文件是否为符号链接
- 判断一个文件是否是符号链接
- java如何判断一个linux下的文件是否为链接文件。
- Java 判断文件是否为图片文件
- python判断对象是否为文件对象(file object)
- java判断文件是否为图片
- java判断文件是否为图片
- Java判断文件是否为图片
- java判断文件是否为图片
- java 判断文件是否为图片2
- Java判断一个文件是否是链接文件
- JAVA之旅(二十八)——File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤
- java判断linux下的符号链接
- Java代码中判断字符是否为中文或中文符号
- 判断文件是否为图片
- 判断文件是否为Unicode
- ASP.NET 配置系统提供以下好处
- 关于系统移植工具
- Java自引用以及陷阱
- C语言字符串操作总结大全(超详细)
- [LeetCode]Roman to Integer
- java File 判断文件是否为符号链接
- Convert
- 探究SYBASE数据库日志
- 前端开发必备 40款优秀CSS代码编写工具推荐
- CCI 指标解释
- 算法导论10.2-8-用一个整数地址替代前后指针实现双向链表
- 计算机概念总结
- iOS UIWebView 与 JavaScript 交互 代码实现 嵌入 js 脚本
- delete Files and Folders(删除文件、文件夹)