不用一个字符一个字符的读,也不要一行一行的读,要一下字把一个文件的所有内容都读到一个字符串中,有这样的函数么

解决方案 »

  1.   

    FileInputStream f = new FileInputStream(fileName);
    byte[] buf = new byte[f.available()];  
    f.read(buf, 0, f.available()); //一次读入
    String str = new String(buf);
      

  2.   

    FileInputStream file = new FileInputStream(fileName);
    byte[] buf = new byte[file.available()];  
    file.read(buf, 0, file.available()); //一次性读入
    String str = new String(buf);多谢!受教了!