在UTF-8编码的Java文件中,删除字符串定义中UTF-8标识符

    public static String removeUTF8Signature(String strKey) throws IOException {
        String resultKey = strKey;
        int index = 0;
        DataInputStream dis=new DataInputStream(new ByteArrayInputStream(strKey.getBytes()));
        while(true) {
            int bb1 = dis.read();
            int bb2 = dis.read();
            int bb3 = dis.read();
            if (bb1 == 0xef && bb2 == 0xbb && bb3 == 0xbf) {
                index+=3;
            } else {
                break;
            }
        }

        resultKey= new String(strKey.getBytes(), index, strKey.getBytes().length - index);
        return resultKey;
    }

 

posted @ 2013-12-02 17:32  Yak Wang  阅读(548)  评论(0)    收藏  举报