用java编写打开一个文件的代码,怎么写?我用api帮助文档找不到方法或者类,

class A{

public void main (sting[] arg){

File a=new File("c:\\1.txt");

a.open();

}

}

我想打开1.TXT这个文件

慕斯卡0096258
浏览 2001回答 3
3回答

xfaini

肯定要用IO流啊

luodongseu

打开文件其实是将文件写入内存。而java将外部文件数据读入内存的接口有FileReader和FileInputStream。具体使用方法可以参考相关类

marlondu

//简单的读文件,具体查java io相关api try {     FileReader in = new FileReader(new File("c:\\1.txt"));     BufferedReader reader = new BufferedReader(in);     String temp = null;     while((temp=reader.readLine())!=null){ System.out.println(temp);     }     reader.close();     in.close(); } catch (Exception e) {     e.printStackTrace(); }
打开App,查看更多内容
随时随地看视频慕课网APP