您的位置:首页 > 编程语言 > Java开发

java中怎样用IO流把一个文件全部读取出来

2014-09-04 16:23 543 查看
public static void main(String[] args)throws Exception{  

String path="d:\\aa.txt";  

File file=new File(path);  

FileInputStream fis=new FileInputStream(file);

InputStreamReader isr=new InputStreamReader(fis,"utf-8");

BufferedReader br=new BufferedReader(isr);

StringBuffer line=new StringBuffer();String str=null;

File file1=new File("d:\\cc.txt");

FileOutputStream fos=new FileOutputStream(file1);

OutputStreamWriter osw=new OutputStreamWriter(fos,"utf-8");

BufferedWriter bw=new BufferedWriter(osw);

while((str=br.readLine())!=null){line.append(str);line.append("\n");

}  

System.out.println(line);bw.flush();bw.close();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  io流