java获取文件的inode标识符的方法
作者:brucelwl 时间:2021-06-19 15:10:49
java获取文件的inode标识符,如果文件被删除或者重命名,inode的值会发生变更,因此可以在第一次加载File之后记录inode,后续校验inode的值来判断文件是否被删除、重命名或重新创建等。
方法1
import java.io.File;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
/**
* Created by bruce on 2022/3/27 21:39
*/
public class FileInodeReaderTest {
public static void main(String[] args) {
File file = new File("/logs/csp/sentinel-block.log");
try {
BasicFileAttributeView basicview = Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class);
BasicFileAttributes attr = basicview.readAttributes();
System.out.println("attr.fileKey():" + attr.fileKey()
+ " attr.creationTime:" + attr.creationTime()
+ " attr.lastModifiedTime:" + attr.lastModifiedTime());
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
方法2
import java.io.File;
import java.nio.file.Files;
/**
* Created by bruce on 2022/3/27 21:39
*/
public class FileInodeReaderTest {
public static void main(String[] args) {
File file = new File("/logs/csp/sentinel-block.log");
try {
Object inode = Files.getAttribute(file.toPath(), "unix:ino");
System.out.println("inode->" + inode);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
补充:Java INode类代码示例
INode类属于org.jbpt.petri包,在下文中一共展示了INode类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getRefinedBondType
import org.jbpt.petri.INode; //导入依赖的package包/类
@Override
public WFTreeBondType getRefinedBondType(IRPSTNode<F,N> node) {
if (node.getType()!=TCType.BOND)
return WFTreeBondType.UNDEFINED;
else {
WFTreeBondType type = this.bond2type.get(node);
if (type!=null) return type;
else {
INode entry = node.getEntry();
INode exit = node.getExit();
if (entry==null || exit == null)
return WFTreeBondType.UNDEFINED;
for (IRPSTNode<F,N> child : this.getChildren(node)) {
if (child.getEntry().equals(node.getExit())) {
type = WFTreeBondType.LOOP;
this.bond2type.put(node,type);
return type;
}
}
if (entry instanceof ITransition && exit instanceof ITransition) {
type = WFTreeBondType.TRANSITION_BORDERED;
this.bond2type.put(node,type);
return type;
if (entry instanceof IPlace && exit instanceof IPlace) {
type = WFTreeBondType.PLACE_BORDERED;
return WFTreeBondType.UNDEFINED;
}
}
}
来源:https://blog.csdn.net/u013202238/article/details/123888271
标签:java,inode,标识符
0
投稿
猜你喜欢
Java创建线程池为什么一定要用ThreadPoolExecutor
2023-04-22 06:03:31
深入理解java内置锁(synchronized)和显式锁(ReentrantLock)
2023-11-19 00:10:57
深入理解Java中的final关键字_动力节点Java学院整理
2022-05-05 23:18:24
简单记事本java源码实例
2023-11-26 02:03:17
Spring Boot+Shiro实现一个Http请求的Basic认证
2022-06-01 22:22:31
SpringMVC结构简介及常用注解汇总
2023-10-25 09:16:59
@Autowired注解注入的xxxMapper报错问题及解决
2022-10-01 10:31:02
java中sleep方法和wait方法的五个区别
2023-08-27 18:37:23
Java客户端调用.NET的WebService实例
2023-11-03 17:22:00
带你了解Java中Static关键字的用法
2021-11-07 15:04:32
Flutter验证码输入框的2种方法实现
2023-07-17 16:22:07
Java截取字符串的几种方法示例
2023-11-29 12:36:32
java编写简易贪吃蛇游戏
2021-08-03 02:53:49
详解Maven settings.xml配置(指定本地仓库、阿里云镜像设置)
2022-04-09 23:45:14
Java快速排序QuickSort(实例)
2021-12-22 21:47:42
Kotlin语言编程Regex正则表达式实例详解
2023-06-22 02:06:29
关于LinkedList集合对元素进行增查删操作
2022-09-23 11:48:45
SpringBoot redis分布式缓存实现过程解析
2023-10-10 22:32:25
2020JDK1.8安装教程详解(一次就可安装成功)
2023-11-28 04:08:58
详解Mybatis是如何解析配置文件的
2023-10-15 23:23:40