所谓流(Stream),就是一系列的数据。

当不同的介质之间有数据交互的时候,java就会使用流来实现。

数据源可以使文件,还可以是数据库,网络,甚至是其他的程序

不如读取文件的数据到程序中,站在程序的角度来看,就叫做输入流

字节输入流:InputStream        字符输入流:Reader    缓存字符输入流:BufferedReader  数据输入流  :DataInputStream               

字节输出流:OutputStream        字符输出流:Writer    缓存字符输出流:PrintWriter    数据输出流:DataOutputStream 

一、I/O操作(流的概念)

1、文件输入流

可以用来把数据从硬盘的文件,读取到JVM(内存)

package stream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class TestStream{
    public static void main(String[] args){
        try{
                File f=new File("d:/lol.txt");
                //创建基于文件的输入流
                FileInputStream fis=new FileInputStream(f);
                //通过这个输入流,就可以把数据从硬盘,读取到java的虚拟机中,也就是读取到内存中
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2021-11-07
  • 2021-12-19
  • 2021-08-27
  • 2021-05-01
  • 2021-05-22
  • 2021-11-07
猜你喜欢
  • 2021-08-31
  • 2022-01-08
  • 2021-05-09
  • 2021-06-04
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案