• java 的文件读取操作


    /**
    *    @param filePath 文件的全路径
    *    返回我们读取到的文件内容
    *
    **/
        public static String readFile(String filePath) {
    
            FileInputStream fis = null;
            StringBuffer sb = new StringBuffer(); // 保存读取的数据
            try {
                
                File file = new File(filePath); // 首先得到文件的位置
                fis = new FileInputStream(file); // 将文件加载到内存中
                InputStreamReader isr = new InputStreamReader(fis, "big5");
                BufferedReader reader = new BufferedReader(isr);
                String line;
                while ((line = reader.readLine()) != null) {
                
                    sb.append(line);  //一次读取一行的数据
                    sb.append("
    ");  //在一行的末尾添加标记方便分隔,或进行其他的处理操作
    
                }
    
    
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (fis != null) {
                        fis.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return sb.toString();
        }

    对于文件的读取操作网上的资料一大堆,自己也是最近用到这个东西,翻着查了一遍,并不算太难,挺简单的,今天有空记录下来方便以后的查询

  • 相关阅读:
    PCA本质和SVD
    特征工程(转载)
    python入门基础代码
    长尾理论
    金融行业数据分析
    [rancher-net]
    rancher中使用ingress-lbs做负载均衡
    python 高级语言特性
    docker从初识到深入
    关于容器技术的发展以及虚拟化技术的总结
  • 原文地址:https://www.cnblogs.com/tangkai/p/3339216.html
Copyright © 2020-2023  润新知