使用Java打开文件的属性窗口 [英] Open a file's properties window using Java
问题描述
这只是Windows中有关Java的问题.
This is a question only regarding Java in Windows.
我需要一个可以调用此窗口的方法:
I need a method that will call this window:
因此,基本上该方法应类似于:
So essentially the method should be something like:
public void openProperties(File file){ // or String fileName
}
因此,语句: opernProperties(new File(test.txt));
应该打开上面的窗口.
So the statement: opernProperties(new File(test.txt));
should open the above window.
因此,为了澄清起见,我不想阅读和管理属性.我只想打开属性窗口.
So just to clarify, I do not want to read and manage the properties. I just want to open the properties window.
推荐答案
我能够使用以下命令显示文件属性窗口:
I was able to display the file properties window using the following:
- 转到 https://oss.sonatype.org/content/repositories/snapshots/net/java/dev/jna/
- 下载快照JAR jna-4.3.0-20160510.203907-1.jar和jna-platform-4.3.0-20160510.204004-1.jar(由于它是4.2,因此我们无法使用maven仓库中的最新版本).2并且没有SHELLEXECUTEINFO)
- 加载罐子并在下面粘贴以下代码
这将显示属性窗口,并延迟3秒.请注意,如果您不希望窗口在3秒后自动关闭,则alk讨论过将窗口传递给hwnd成员
This should display the properties window with a delay of 3 seconds. Notice that alk talked about passing the window through hwnd member if you don't want it to auto close after the 3 seconds
public static void main(String[] args) throws InterruptedException {
ShellAPI.SHELLEXECUTEINFO shellExecuteInfo = new ShellAPI.SHELLEXECUTEINFO();
shellExecuteInfo.lpFile = "C:\\setup.log";
shellExecuteInfo.nShow = User32.SW_SHOW;
shellExecuteInfo.fMask = 0x0000000C;
shellExecuteInfo.lpVerb = "properties";
if (Shell32.INSTANCE.ShellExecuteEx(shellExecuteInfo)){
Thread.sleep(3000);
}
}
这篇关于使用Java打开文件的属性窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!