zoukankan      html  css  js  c++  java
  • java 读取文件内容

    //读取方法

    public static String txt2String(String path){
      String fileContent = "";
      try
       {
        File f = new File(path);
        if(f.isFile()&&f.exists())
        {
          InputStreamReader read = new InputStreamReader(new FileInputStream(f),"gbk");
          BufferedReader reader=new BufferedReader(read);
          String line;
          while ((line = reader.readLine()) != null)
          {
            fileContent += line;
          }
            read.close();
        }
      } catch (Exception e)
      {
        e.printStackTrace();
      }
      return fileContent;
    }

    //测试main方法
    public static void main(String[] args) {
    String a=txt2String("C:/Users/A12080084/Desktop/Test.html");
    System.out.println(a);
    System.out.println(a.length());
    }

  • 相关阅读:
    C 语言实例
    C 语言实例
    C 语言实例
    C 语言实例
    C 语言实例
    C 语言实例
    C 语言实例
    C 语言实例
    YQCB冲刺第二周第二天
    YQCB冲刺第二周第一天
  • 原文地址:https://www.cnblogs.com/xiaowenwu/p/5130022.html
Copyright © 2011-2022 走看看