码迷,mamicode.com
首页 > 编程语言 > 详细

Java中IO对象的输入输出流

时间:2019-06-25 16:38:13      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:int   输出流   txt   java   input   stream   tput   throws   dem   

输入流:

public void inputDemo () throws IOException {
  //文件名称 String fileName
= "d:\\aaa.txt";
  //通过文件名称创建文件对象 File file
= new File(fileName);   
  //创建一个输入流对象
// new FileOutputStream(file); FileInputStream fis = new FileInputStream(fileName); // int c; // while ((c = fis.read()) > 0) { // System.out.print((char)c); // }   //创建一个字节数组 byte[] buf = new byte[2000]; int len;
  //没有找到内容返回-1,所以判断有没内容。有则输出
while ((len = fis.read(buf)) > 0) { System.out.println("新的一杯:"); System.out.println(new String(buf)); }   //关闭输入流 fis.close(); }

输出流:

  

public void outputDemo () throws IOException {
  //创建输出对象流 FileOutputStream fos
= new FileOutputStream("d:\\bbb.txt");
  //通过输出创建写入流 OutputStreamWriter writer
= new OutputStreamWriter(fos);
  //通过写入流写入内容 writer.write(
"hello, output stream"); writer.close(); }

 

Java中IO对象的输入输出流

标签:int   输出流   txt   java   input   stream   tput   throws   dem   

原文地址:https://www.cnblogs.com/LixiaoFeng1650062546/p/11083529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!