Best way to build a String out of characters

This question already has an answer here:

  • Read/convert an InputStream to a String 56 answers

  • 你可以做类似的事情

    public String readTextFile(File file) {
          StringBuilder sb = new StringBuilder();
          try(BufferedReader br = new BufferedReader(new FileReader(file))){
              String line;
              while ((line = br.readLine()) != null){
                  sb.append(line);
              }
          }
          return sb.toString();
    }
    
    链接地址: http://www.djcxy.com/p/13744.html

    上一篇: 如何从网站获取我的数据,以便我可以解析它?

    下一篇: 从字符中构建字符串的最佳方法