0

I want to read a file(like .txt) and do std::cout.

but if the file's locale doesn't same with my system's locale, it will print weird.

this is my question. how can I know the file's locale?

if I can get file's locale, I can change system's locale to file's locale and it will print clearly.

Kim
  • 1

1 Answers1

0

Read file using something like:

new InputStreamReader(new FileInputStream(...), )

For encoding Use the required encoding based on file source, you can guess that or try UTF-8 for a test.

Example:

String file = "file location";
    String encoding = "utf-8";
    try {
        new InputStreamReader(new FileInputStream(file), encoding);
    } catch (UnsupportedEncodingException e) {
        System.out.println("Encoding Uknown " + encoding);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }       
Babajide Prince
  • 552
  • 1
  • 10
  • 25