0

Need to read a json file that is in "UCS-2 LE BOM" or "UTF-8 BOM" encoding format. The below code read json from UTF-8

    JSONParser parser = new JSONParser();
    InputStream inputStream = new FileInputStream(inputJsonPath);
    Reader fileReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
    Object obj = parser.parse(fileReader);
    org.json.simple.JSONObject inputJsonObject = (org.json.simple.JSONObject) obj;
Ashish Goyanka
  • 207
  • 3
  • 11
  • If you insist on UCS-2 and really don't mean UTF-16 then as per comments to [this answer](https://stackoverflow.com/a/64863428/4299358) you can try `Charset.forName("UnicodeLittle")`. – AmigoJack May 28 '21 at 13:05
  • Use `StandardCharsets.UTF_8` or `StandardCharsets.UTF-16LE`, check if the 1st line starts with a BOM `"\uFEFF"` and remove it prospectively… – JosefZ May 28 '21 at 13:12

0 Answers0