zoukankan      html  css  js  c++  java
  • java读取本地文件

    File file = new File("F:/hejing/InstrumentJsonData.txt");
            StringBuilder localStrBulider = new StringBuilder();
            if(file.isFile() && file.exists()) {
                try {
                    InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), "utf-8");
                    BufferedReader bufferReader = new BufferedReader(inputStreamReader);
                    String lineStr = null;
                    try {
                        while((lineStr = bufferReader.readLine()) != null) {
                            localStrBulider.append(lineStr);
                        }
                        bufferReader.close();
                        inputStreamReader.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        System.out.println("file read error!");
                        e.printStackTrace();
                    }
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    System.out.println("file catch unsupported encoding!");
                    e.printStackTrace();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    System.out.println("file not found!");
                    e.printStackTrace();
                }
            }else {
                System.out.println("file is not a file or file is not existing!");
                return null;
            }
            System.out.println("localStrBulider.toString():" + localStrBulider.toString());

  • 相关阅读:
    判断点是否在一个任意多边形中
    linux 内存布局以及tlb更新的一些理解
    java(内部类)
    java(面向对象 )
    java(数组及常用简单算法 )
    java(运算符,控制流程语句,函数 )
    deep-in-es6(七)
    Java(标识符,关键字,注释,常量,变量)
    MarkDown study:
    *LeetCode--Ransom Note
  • 原文地址:https://www.cnblogs.com/hejing-swust/p/7986593.html
Copyright © 2011-2022 走看看