I/O

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

按流向分:输出流和输入流,输出流主要由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();
   }
  }
 
 }
}
posted @ 2020-05-31 22:28  平常心看待  阅读(235)  评论(0)    收藏  举报