java獲取文件的inode標(biāo)識符的方法
java獲取文件的inode標(biāo)識符,如果文件被刪除或者重命名,inode的值會發(fā)生變更,因此可以在第一次加載File之后記錄inode,后續(xù)校驗(yàn)inode的值來判斷文件是否被刪除、重命名或重新創(chuàng)建等。
方法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());
}
}
}
補(bǔ)充:Java INode類代碼示例
INode類屬于org.jbpt.petri包,在下文中一共展示了INode類的1個代碼示例,這些例子默認(rèn)根據(jù)受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點(diǎn)贊,您的評價將有助于我們的系統(tǒng)推薦出更棒的Java代碼示例。
示例1: getRefinedBondType
import org.jbpt.petri.INode; //導(dǎo)入依賴的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;
? ? ? ? }
? ? }
}到此這篇關(guān)于java獲取文件的inode標(biāo)識符的方法的文章就介紹到這了,更多相關(guān)java inode標(biāo)識符內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java中CAS機(jī)制實(shí)現(xiàn)方法詳解
傳統(tǒng)的并發(fā)控制手段如synchronized和ReentrantLock雖有效防止資源競爭,卻可能引起性能開銷,相比之下,CAS(CompareAndSwap)提供一種輕量級的樂觀鎖策略,通過硬件級別的原子指令實(shí)現(xiàn)無鎖并發(fā),提高性能,需要的朋友可以參考下2024-09-09
Springboot多數(shù)據(jù)源配置之整合dynamic-datasource方式
這篇文章主要介紹了Springboot多數(shù)據(jù)源配置之整合dynamic-datasource方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03
搭建Spring MVC和Vue3的應(yīng)用程序的實(shí)現(xiàn)
本文主要介紹了搭建Spring MVC和Vue3的應(yīng)用程序的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-11-11
深入淺出分析Java抽象類和接口【功能,定義,用法,區(qū)別】
這篇文章主要介紹了Java抽象類和接口,結(jié)合實(shí)例形式深入淺出的分析了java抽象類與接口的功能功能,定義,用法及區(qū)別,需要的朋友可以參考下2017-08-08
Java集合基礎(chǔ)知識 List/Set/Map詳解
這篇文章主要介紹了Java集合基礎(chǔ)知識 List/Set/Map,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03

