怎么用Java实现打开文件(打开方法)?

Python012

怎么用Java实现打开文件(打开方法)?,第1张

Process p = Runtime.getRuntime().exec("notepad").

可以用java执行cmd命令的方式打开程序,比如上面是打开windows记事本的指令。如果你要打开其他文件,那就把notepad改成对应的文件名或程序名

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()

}

}

}