首页 > 其他 > 详细

I/O

时间:2020-06-01 00:10:58      阅读:82      评论:0      收藏:0      [点我收藏+]

流:是指一连串流动的字符,是以先进先出的方式发送和接收数据的通道。

按流向分:输出流和输入流,输出流主要由OutputStream和Write作为基类,而输入流主要由InputSteam和Reader作为基类。

输入流和输出流又分为字节流和字符流,字节输入流InputSteam作为基类,字节输出流OutputStream作为基类。

package cc.kgc.yy;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FileInput {
 public static void main(String[] args) {
  File f=new File("hello.txt");  //创建File类
  FileInputStream file=null;//选择合适的流
  try {
   file=new FileInputStream (f);
   int read = file.read();
   while(read!=-1){
   System.out.print((char)read);
   read = file.read();
   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally{
   try {
    file.close();//关流
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 
 }
}

I/O

原文:https://www.cnblogs.com/yangyi88929/p/13022055.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!