如何在Windows上使用Java在默认图像查看器中打开图像?
发布时间:2020-12-14 04:19:16 所属栏目:Windows 来源:网络整理
导读:我有一个按钮来查看附加到日志条目的图像,当用户单击该按钮时,我希望它在 Windows机器上的用户默认图像查看器中打开图像? 如何知道默认图像查看器中的哪个查看器? 现在我正在做这样的事情,但它不起作用: String filename = """+(String)attachmentsCombo
我有一个按钮来查看附加到日志条目的图像,当用户单击该按钮时,我希望它在
Windows机器上的用户默认图像查看器中打开图像?
如何知道默认图像查看器中的哪个查看器? 现在我正在做这样的事情,但它不起作用: String filename = """+(String)attachmentsComboBox.getSelectedItem()+"""; Runtime.getRuntime().exec("rundll32.exe C:WINDOWSSystem32shimgvw.dll,ImageView_Fullscreen "+filename); 并且通过不起作用我的意思是它什么都不做.我试图在命令行中运行该命令,但没有任何反应.没错,没什么.
尝试使用CMD / C START
public class Test2 { public static void main(String[] args) throws Exception { String fileName = "c:temptest.bmp"; String [] commands = { "cmd.exe","/c","start",""DummyTitle"",""" + fileName + """ }; Process p = Runtime.getRuntime().exec(commands); p.waitFor(); System.out.println("Done."); } } 这将启动与文件扩展名关联的默认照片查看器. 更好的方法是使用java.awt.Desktop. import java.awt.Desktop; import java.io.File; public class Test2 { public static void main(String[] args) throws Exception { File f = new File("c:temptest.bmp"); Desktop dt = Desktop.getDesktop(); dt.open(f); System.out.println("Done."); } } 见Launch the application associated with a file extension (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在Windows上检查Ruby中的文件版本
- windows – 如何使用VBScirpt在已打开的CMD窗口中执行命令
- windows下配置php5.5开发环境及开发扩展
- windows-update – 从Microsoft Update更新的WSUS客户端
- Windows上的TortoiseSVN – 结帐错误“…在目录中不是有效的
- Windows Mobile:使用C#的手机摄像头
- windows-server-2008 – 适用于Windows 2008 / SQL Server群
- 在Windows Phone 7上使用MySQL数据库?
- Windows – 使用cmd.exe以UTF-8编码保存文本文件
- 如何为Windows应用程序注册自定义键盘快捷方式
推荐文章
站长推荐
- Windows Defender Antivirus从C#扫描[AccessViol
- Windows 2003 DHCP服务器 – 使用BAD ADDRESS条目
- 如何在Windows窗体中使用MVVM来显示WPF控件
- 为什么我只能在Windows 2008 R2中创建1个2TB卷?
- 在Windows上具有常量输出的Python无块子进程输入
- windows – 如何通过.bat文件从任务计划程序运行
- windows-server-2008 – Windows 7 x64 Ultimate
- winapi – Win32 ReadFile从管道读取时挂起
- ms-access – 如何从外部程序设置Microsoft Acce
- iis – 访问注册表项“全局”被拒绝
热点阅读