number2

来源:互联网 发布:瓷砖专用进销存软件 编辑:程序博客网 时间:2024/05/21 08:05

FileInputStream:

FileInputStream in = null; int b =0;

try{

        in = new FileInputStream("要打开的目录");//FileInputStream会抛异常,两种方法解决异常,catch || throws

} catch(FileNOtFoundException e){

          System.out.println("如何处理异常");
}

try{

         while( (b = in.read()) != -1){

                 System.out.println((char)b);

           }

}catch(IOException e){

        System.out.println(" ");

}

 

in.close();//important

 

1.先声明一引用是字符流还是字节流

2然后让引用指向所需要操作的文件

3判断会不会抛出异常

4然后调用流里的方法

5文件用完要关闭close