您的位置 首页 java

Java按行读取文件

 public void tempImportJumpLog(String filePath){
        File file = new File(filePath);
        try {
            BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file));
            // 用5M的缓冲读取文本文件
            BufferedReader reader = new BufferedReader(new InputStreamReader(fis,"utf-8"),5*1024*1024);
            String line = "";
            int i=1;

            while((line = reader.readLine()) != null){
                //TODO: write your business
                if(StringUtils.isNotEmpty(line)){
                    kafkaTemplate.send("data-monitor", line);
                }else{
                }
                i++;
                System.out.println("send msg to kafka:"+i);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }  

文章来源:智云一二三科技

文章标题:Java按行读取文件

文章地址:https://www.zhihuclub.com/181300.shtml

关于作者: 智云科技

热门文章

网站地图