zoukankan      html  css  js  c++  java
  • [工具类] 文件

    package com.claw.util.file;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.apache.hadoop.util.StringUtils;
    
    import com.claw.util.string.StringUtil;
    
    public class FileUtil {
        
        public static void main(String[] args) {}
        
        public static List<String> readFile(String filePath){
            List<String> list = new ArrayList<String>();
            try {
                    String encoding="UTF-8";
                    File file=new File(filePath);
                    //判断文件是否存在
                    if(file.isFile() && file.exists()){ 
                        InputStreamReader read = new InputStreamReader(new FileInputStream(file),encoding);//考虑到编码格式
                        BufferedReader bufferedReader = new BufferedReader(read);
                        String lineTxt = null;
                        while((lineTxt = bufferedReader.readLine()) != null){
                            List<String> lineList  = StringUtil.getLine(lineTxt+"	");
                            if(lineList!=null && lineList.size()==4){
                                String url = lineList.get(3);
                                if(!"".equals(url)){
                                    list.add(url);
                                }
                            }else{
                                break;
                            }
                        }
                        read.close();
            }else{
                System.out.println("找不到指定的文件");
            }
            } catch (Exception e) {
                System.out.println("读取文件内容出错");
                e.printStackTrace();
            }
            return list;
        }
        
    }
  • 相关阅读:
    卷积操作特征图输出大小
    python函数式编程
    python函数
    列表和元组
    Crontab 执行时没有环境变量!
    github 解决 Agent admitted failure to sign using the key
    Lightgbm 随笔
    btrfs-snapper 实现Linux 文件系统快照回滚
    Ansible playbook API 开发 调用测试
    Linux终端下安装jdk
  • 原文地址:https://www.cnblogs.com/feelgood/p/4992100.html
Copyright © 2011-2022 走看看