Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 确定文件是否为内容索引(在Windows中)?_Java_Windows_Winapi - Fatal编程技术网

Java 确定文件是否为内容索引(在Windows中)?

Java 确定文件是否为内容索引(在Windows中)?,java,windows,winapi,Java,Windows,Winapi,Java问题 我应该使用什么方法来确定Windows文件是否标记为内容索引?我试图编写一个类似于的解决方案,我想强调的是,下面的代码是在简单假设.getClass().getDeclaredMethod方法确实有“isIndexed”作为参数的情况下编写的,但是,这种假设是不正确的,因为下面的代码总是返回false。我决定将其保留,以防有人知道适合此代码的正确引用 boolean isIndexed = false; if (DosFileAttributes.class.isInstance(

Java问题

我应该使用什么方法来确定Windows文件是否标记为内容索引?我试图编写一个类似于的解决方案,我想强调的是,下面的代码是在简单假设.getClass().getDeclaredMethod方法确实有“isIndexed”作为参数的情况下编写的,但是,这种假设是不正确的,因为下面的代码总是返回false。我决定将其保留,以防有人知道适合此代码的正确引用

boolean isIndexed = false;
if (DosFileAttributes.class.isInstance(attr)) {
    try {
         Method m = attr.getClass().getDeclaredMethod("isIndexed");
         m.setAccessible(true);
         isIndexed = (boolean) m.invoke(attr);
    } catch (Exception e) {
         // just gave it a try
    }
}
除了getDeclaredMethod参数中的“isIndexed”,我还尝试使用“isContentIndexed”和“isNotContentIndexed”,但都没有任何令人满意的结果。

该类没有任何方法来报告文件是否为内容索引。但是,您可以调用
attributes()
方法来检索文件属性的底层位掩码,然后检查是否设置了
file\u属性\u NOT\u CONTENT\u index
(0x2000)属性位:

boolean isIndexed = false;
if (DosFileAttributes.class.isInstance(attr)) {
    isIndexed = true;
    try {
         Method m = attr.getClass().getDeclaredMethod("attributes");
         m.setAccessible(true);
         int attrs = (int) m.invoke(attr);
         isIndexed = ((attrs & 0x2000) == 0);
    } catch (Exception e) {
         // just gave it a try
    }
}

为什么您认为名为
的方法是indexed
存在的?我看不出有什么理由?您在哪里找到它存在的文档?首先,您需要了解您复制的“n”粘贴的代码。没有这样的方法
是索引的
,至少这就是为什么它不起作用的原因。对于第二部分:唯一的可能是通过JNI、JNA等使用一些Windows系统调用@DavidHeffernan我不知道。我试了一下。好吧,我要停止投稿了,因为我的评论被删除了。@DavidHeffernan听到这个消息我很难过,David。我没有报告你或任何事情,我当然可以理解为什么你会嘲笑我猜测了这么一个模糊函数的方法名。一如既往,
sun.*
类应该被视为在未来的Java版本中随时更改,恕不另行通知。私有方法也是如此。另一种方法是使用JNA直接调用Win32
GetFileAttributes()
FindFirstFile()
函数。