编程语言
首页 > 编程语言> > 基础知识 Java 文件读取 行读 字节读取

基础知识 Java 文件读取 行读 字节读取

作者:互联网

        //字节流 行读取 String
        File file = new File("C:\\Users\\Administrator\\Desktop\\test.txt");

        BufferedReader bufferedReader = new BufferedReader(new FileReader(file));

        String tempString = null;
        while( (tempString = bufferedReader.readLine()) != null){
            System.out.print(tempString);
        }

        bufferedReader.close();


        //字节读取   int
        FileInputStream fileInputStream = new FileInputStream(("C:\\Users\\Administrator\\Desktop\\test.txt"));
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");

        int temp;
        while((temp = inputStreamReader.read()) != -1){
            System.out.print((char)temp);
        }
        inputStreamReader.close();

 

 

 


 

 

 

      基础

 

标签:Java,读取,temp,bufferedReader,tempString,new,inputStreamReader,行读
来源: https://www.cnblogs.com/misscai/p/14220289.html