i am trying to read UTF 8 file with BOM char .. if BOM mark present then i want to remove that BOM char
and write same file with UTF16LE with out BOM char ..
Please suggest solution on this .
FileInputStream fis = new FileInputStream(file);
long size = file.length();
byte[] b = new byte[(int) size];
int bytesRead = fis.read(b, 0, (int) size);
if (bytesRead != size) {
throw new IOException("cannot read file");
}
byte[] srcBytes = b;
int b0 = srcBytes[0] & 0xff;
int b1 = srcBytes[1] & 0xff;
int b2 = srcBytes[2] & 0xff;
int b3 = srcBytes[3] & 0xff;
if (b0 == 0xef && b1 == 0xbb && b2 == 0xbf) {
System.out.println("Hint: the file starts with a UTF-8 BOM.");
}
String srcStr = new String(b ,"UTF8");
String encoding= "UnicodeLittle";
writeFile(filePath, srcStr,encoding);// Here is writing file with UTF16LE
But files gets written with BOM char .
how do i remove this .
Please suggest solution on this