Java It is not possible to read a previously created encoded file correctly.

I have a problem reading the encoded file previously overlaid on my own code.

The original line is displayed correctly (including accent marks)

My code for storing a string in an encoded file is as follows:

OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fileName),
      "ISO-8859-1");
writer.write(text);

Then I read the file as follows:

InputStream is = getClass.getResourceAsStream(fileName);

try {           
    BufferedReader br = new BufferedReader(new InputStreamReader(is, "ISO-8859-1"));
    String line;
    StringBuilder sb = new StringBuilder();

    while( (line = br.readLine()) != null ) {
        sb.append(line);
    }

    String result = sb.toString();
} catch (UnsupportedEncodingException e3) {
} catch (IOException e) { }

The result of the line is not displayed correctly. For example, there are no accent marks.

I also tried other ways, such as encoding String in bytes, and then writing these bytes to a file. I always get the same results as other ISO encodings. Any idea?

+4
source share
2 answers

, , UTF-16.

0

!

- ​​. , Maven.

, Maven , UTF-8. , , , UTF-8, Maven.

, , Maven, , .

!

0

Source: https://habr.com/ru/post/1650636/


All Articles