//读取方法

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());
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-23
  • 2022-12-23
  • 2022-02-08
  • 2021-06-01
猜你喜欢
  • 2022-12-23
  • 2022-01-01
  • 2021-05-18
  • 2022-02-07
  • 2022-01-18
  • 2022-02-09
  • 2021-09-05
相关资源
相似解决方案