以writer,reader结尾的是字符流以stream结尾的是字节流
package practice; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class Test { public static void main(String[] args) { FileInputStream fis = null; try { //创建文件字节输入流对象 //文件路径"C:\\Users\\17222\\Desktop\\插入排序.docx" // fis =new FileInputStream("C:/Users/17222/Desktop/插入排序.docx"); //开始读 int readData = fis.read(); System.out.println(readData); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { //在finally语句块中确保流一定关闭 if (fis !=null){//避免空指针异常!关闭流的前提是流不为空 try{ fis.close(); }catch(IOException e){ e.printStackTrace(); } } } } }
int readCount是方法的返回值 返回字节的数量