java获取文件的inode标识符的方法

网友投稿 292 2022-08-16


java获取文件的inode标识符的方法

java获取文件的inode标识符,如果文件被删除或者重命名,inode的值会发生变更,因此可以在第一次加载File之后记录inode,后续校验inode的值来判断文件是否被删除http://、重命名或重新创建等。

方法1

import java.io.File;

import java.nio.file.Files;

import java.nio.file.attribute.BasicFileAttributeView;

import java.nihttp://o.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.Filhttp://e;

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 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 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;

}

}

}


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:dubbo入门指南及demo实例详解
下一篇:Spring Framework远程代码执行漏洞分析(最新漏洞)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~