java獲取文件的inode標識符的方法
java獲取文件的inode標識符,如果文件被刪除或者重命名,inode的值會發(fā)生變更,因此可以在第一次加載File之后記錄inode,后續(xù)校驗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()); } } }
補充:Java INode類代碼示例
INode類屬于org.jbpt.petri包,在下文中一共展示了INode類的1個代碼示例,這些例子默認根據(jù)受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點贊,您的評價將有助于我們的系統(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標識符的方法的文章就介紹到這了,更多相關(guān)java inode標識符內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot結(jié)合JWT登錄權(quán)限控制的實現(xiàn)
本文主要介紹了SpringBoot結(jié)合JWT登錄權(quán)限控制的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07java環(huán)境變量path和classpath的配置
這篇文章主要為大家詳細介紹了java系統(tǒng)環(huán)境變量path和classpath的配置過程,感興趣的小伙伴們可以參考一下2016-07-07