用java打开文件 [英] opening a file in java
本文介绍了用java打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过Java程序打开文件.该文件应在系统的默认程序中打开.
例如:应在记事本中打开一个文本文件.
图片应在默认的图片查看器中打开.
有哪些可能的方法来实现呢?
我想编写一个函数,将类File的对象传递给该函数,并且该函数必须打开文件.
感谢
I want to open a file through a java program.The file should open in the system''s default program.
for e.g.:a text file should open in notepad.
an image should open in default image viewer.
what are the possible ways of implementing this?
i want to write a function to which i will pass an object of class File and the function has to open the file.
thanks
推荐答案
File file = new File("myFile.txt");
Desktop.getDesktop().open(file);
这篇关于用java打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文