java 打开file文件,实现下面两个方法

2025-02-23 13:14:03
推荐回答(5个)
回答1:

import java.io.IOException;
public void open(File file){
Runtime.getRuntime().exec("cmd.exe /c start D:\\ibatis");
}

实现打开了。。 你把路径编程你对应的路径就OK了。。回答一半给不给分呢?

回答2:

public void open(File file){
String str=null;
try {
FileInputStream fr = new FileInputStream(file);
InputStreamReader is = new InputStreamReader(fr,"UTF-8");
BufferedReader br=new BufferedReader(is);
while((str=br.readLine())!=null){
System.out.println(str);
}
br.close();
is.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
java读取文件不需要关闭方法,直接把流关闭就可以了

回答3:

File f=new File("路径");
FileInputStream fis=new FileInputStream(f);

回答4:

用数据流啊

回答5:

不懂