Converting byte array to String (Java)

前端 未结 7 1028
不知归路
不知归路 2020-11-28 06:29

I\'m writing a web application in Google app Engine. It allows people to basically edit html code that gets stored as an .html file in the blobstore.

I\

7条回答
  •  遥遥无期
    2020-11-28 07:04

    public static String readFile(String fn)   throws IOException 
    {
        File f = new File(fn);
    
        byte[] buffer = new byte[(int)f.length()];
        FileInputStream is = new FileInputStream(fn);
        is.read(buffer);
        is.close();
    
        return  new String(buffer, "UTF-8"); // use desired encoding
    }
    

提交回复
热议问题