List of utility methods to do File Encode Guess
String | guessEncoding(File file) guess Encoding FileInputStream fis = null; try { fis = new FileInputStream(file); return FileUtil.guessEncoding(fis); } catch (Exception e) { return null; } finally { if (fis != null) { ... |
String | guessEncoding(InputStream inputStream) guess Encoding try { byte[] rs = getFileByte(inputStream); String str = new String(rs, ENCODE_UTF8); if (str.equals(new String(str.getBytes(), ENCODE_UTF8))) { return ENCODE_UTF8; } else { str = new String(rs, ENCODE_GBK); if (str.equals(new String(str.getBytes(), ENCODE_GBK))) { ... |
String | guessEncoding(File file) Try to guess the file encoding. byte[] b = readFile(file, 3); String guess = null; if (b[0] == (byte) 0xef && b[1] == (byte) 0xbb && b[2] == (byte) 0xbf) guess = UTF8; else if (b[0] == (byte) 0xff && b[1] == (byte) 0xfe) guess = UTF16LE; else if (b[0] == (byte) 0xfe && b[1] == (byte) 0xff) ... |
String | getEncodingOfXml(File file) Try to find the encoding of a xml file. byte[] bs = readFile(file, 150); String encoding = "utf-8"; boolean findEncoding = false; Map chars = Charset.availableCharsets(); Set keys = chars.keySet(); Iterator iterator = keys.iterator(); Pattern pattern = Pattern.compile("encoding=\"([^\"]*?)\""); while (iterator.hasNext()) { ... |