2

My application users need to upload a text file containing unicode(UTF-8) characters, but at the server side when converting the File contents the unicode characters are getting lost.

For example: BleȬÁno is converted into Ble?Áno.

   public String getUploadFileAsString() {
        try {
            final InputStream stream = file.getInputStream();
            final StringWriter writer = new StringWriter();
            IOUtils.copy(stream, writer, Charsets.UTF_8);
            return writer.toString();
        } catch (final IOException e) {
            throw new Exception("exception in getUploadFileAsString()", e);
        }
    }
Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
  • Is the code shown in your question the server code or the client code? What happens to the string returned by this method? How is the file originally created? – DodgyCodeException May 09 '18 at 12:10
  • Possible duplicate of [Read/convert an InputStream to a String](https://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string) – Bartosz Bilicki May 09 '18 at 14:24
  • 2
    Are you absolutely sure the file is UTF-8? – Mark Rotteveel May 10 '18 at 11:51
  • For me in place of “ � was appearing. I used the option "convert to utf-8" in notepad++ after which on upload this character was coming properly. – Nikhil Nov 19 '20 at 18:53

0 Answers0