• 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下搭建socks5代理
    在vs2005 使用FreeTextBox
    毕业了!!
    ASP.net 2.0上传图片方法
    再网页中,怎么用VS2005中的日历空件输入日期格式!
    毕业设计!!
    学校终于放假了,今天就可以回家了!
    求职!本人是07届刚毕业的学生!求程序员
    libcurl教程(转)
    spring boot集成swagger3
  • 原文地址:https://www.cnblogs.com/hejing-swust/p/7986593.html
Copyright © 2020-2023  润新知