Java tutorial
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; public class Main { public static final String UTF8_BOM = "\uFEFF"; private static boolean hasUTF8BOM(File f) throws FileNotFoundException, IOException { FileInputStream fis = new FileInputStream(f); BufferedReader br = new BufferedReader(new InputStreamReader(fis, Charset.forName("UTF-8"))); String s = br.readLine(); boolean ret = false; if (s.startsWith(UTF8_BOM)) ret = true; br.close(); return ret; } }