缓冲字符流

class  Demo
{
    public static void main(String[] args) 
    {
        //缓冲字符流分为缓冲输入字符流和缓冲输出字符流
        //BufferedReader 缓冲输入字符流目的是提高读文件的效率
//也是维护一个字符数组。他是一这个字符数组作为缓冲的
    //找到目标文件
        File file = new File("D:/71期Java课堂/12月17日/hello.txt");
        //建立数据通道
        FileReader reader = new FileReader(file);

      String line = null;
     while((line = myReadLine(reader)) != null){

            System.out.println(line);
        }

        public static void readTest1() throws IOException{

        //找到目标文件
        File file = new File("D:/71期Java课堂/12月17日/hello.txt");
        //建立数据通道
        FileReader reader = new FileReader(file);
        //建立缓冲输入字符流
    BufferedRreader bufferedReader = new BufferedReader(reader);

     //读数据,读取每一行的数据
     String line = null;
     while (line = bufferedReader.readLine() != null)
     {
         System.out.println(line);

     }

     bufferedReader.close();


    }

//自己模拟readline方法的内部实现
public static Stirng myReadLine(FileReader fileReader)
        {

StringBuffer buffer =new StringBuffer();
int content = 0;
while (cintent = fileReader.read()! =-1)
{
    if (content =='\r')
    {
        continue;
    }else if (conten == '\n')
    {
        break;

    }else {
     buffer.append((char)content);

    }
}

if (cintent!= -1)
{
    return buffer.toString()//转换为字符串、

}
return null;
}
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值