服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - java获取文件的inode标识符的方法

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

2022-10-31 11:03brucelwl Java教程

这篇文章主要介绍了java获取文件的inode标识符,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

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

方法1

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
        }
    }
}

到此这篇关于java获取文件的inode标识符的方法的文章就介绍到这了,更多相关java inode标识符内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/u013202238/article/details/123888271

延伸 · 阅读

精彩推荐