Load UTF8 encoded file to String : UTF « Development « Android






Load UTF8 encoded file to String

 

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

class Utils {

  public static String loadFile(String fileName) throws IOException {
    StringBuffer buffer = new StringBuffer();
    FileInputStream fis = new FileInputStream(fileName);
    InputStreamReader isr = new InputStreamReader(fis, "UTF8");
    Reader in = new BufferedReader(isr);
    int ch;
    while ((ch = in.read()) > -1) {
      buffer.append((char) ch);
    }
    in.close();
    return buffer.toString();
  }

}

   
  








Related examples in the same category

1.decode UTF8 to char
2.decode UTF8 to String
3.implements InputFilter
4.UTF 2 GBUtil
5.UTF8 to Byte Array