Converting byte array to String (Java)

0 views
Skip to first unread message

craig via StackOverflow

unread,
Jul 9, 2013, 12:29:11 AM7/9/13
to google-appengin...@googlegroups.com
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
}


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/5673059/converting-byte-array-to-string-java/17539803#17539803
Reply all
Reply to author
Forward
0 new messages