㈠ 怎么用java实现打开文件(打开方法)
Process p = Runtime.getRuntime().exec("notepad");.
可以用java执行cmd命令的方式打开程序,比如上面是打开windows记事本的指令。如果你要打开其他文件,那就把notepad改成对应的文件名或程序名
㈡ Java打开指定文件
java打开文件夹使用方法:
String strTmp= "D:\abc\";
Runtime.getRuntime().exec("explorer.exe" + strTmp);
java读取文件使用方法:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class OpenFile {
public static void main(String args[]) {
try {
BufferedReader br = new BufferedReader(new FileReader("c://EmailSpider.java"));
String line = "";
while((line=br.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
㈢ 如何用java打开一个本地文件
上代码
String[]cmd=newString[]{
"cmd.exe",
"/c",
//第三个参数就是你要打开的文件路径
"D:\Work\workspace\GIFRecorder.rar"
};
Runtime.getRuntime().exec(cmd);
㈣ 怎样用java打开指定文件
File file = new File("文件绝对路径");
Desktop.getDesktop().open(file);
即可调用系统的默认打开工具,打开这个文件