如何使用Java打开和查看文件(类似于双击文件)
我想知道 Java 中的代码,这将有助于执行与在任何操作系统中双击打开文件相同的操作,从而使我们能够在用户提供文件位置时查看其内容文件在他/她的电脑中。任何建议都会有很大帮助,因为我需要它来完成我的申请。
I would like to know to know the code in Java that that will help perform the same operation as that of a double click in any OS on a file making it open and thereby enable us to view its contents when the user supplies the location of the file in his/her PC. Any suggestion would be of great help as i need it to finish my application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅桌面。打开(文件)
See Desktop.open(File)
我使用了以下代码。在 Windows 上,如果没有程序与该文件类型关联,您将看到一个 Windows 文件打开对话框。如果它不在 Windows 上运行,它将回退到
Desktop.open()
,如果系统已知文件类型,该方法就可以工作。I used the following code. On windows, you will get a windows file open dialog if no program is associated with the file type. If it does not run on windows, it falls back to
Desktop.open()
, which works if the file type is known to the system.在Windows XP中:
您可以添加注册表,以便可以在“运行”对话框和文件夹巡洋舰中运行lnk文件:
in windows xp:
you could add registry so that you could run lnk file in RUN dialog box and folder cruiser: