0

I load a txt file as a collection of strings, then I save it in a Database HSQLDB. When i load from DB and print a TextArea The output type of text is this:

Quando il flusso � maggiore nella narice di destra � la Nadi Pingala a predominare. L'energia vitale � molto pi� attiva e di conseguenza saremo pi� forti fisicamente, saremo pi� introversi e solari. Durante il sonno tende a non.

How I can format it normally?

Mạnh Quyết Nguyễn
  • 17,677
  • 1
  • 23
  • 51
  • 1
    You should show us how you read from txt file, how your txt file is encoded and how you store and retrieve to/from DB – Mạnh Quyết Nguyễn May 24 '18 at 14:22
  • Is this being printed in Eclipse console? If so, have you set its char encoding to allow printing of your chars of interest? Please read: https://stackoverflow.com/questions/36030836/date-string-is-showing-question-marks – Hovercraft Full Of Eels May 24 '18 at 14:22
  • I load a txt file with those instructions in eclipse : byte[] encoded = Files.readAllBytes(Paths.get(file.getPath())); t_inserimentoTItolo.setText(file.getName().substring(0, file.getName().indexOf("."))); return new String(encoded, "UTF-8"); – Christian Scarselli May 24 '18 at 14:23
  • And i load from DB with a classic ResultSet, the data are salved as VARCHAR – Christian Scarselli May 24 '18 at 14:25

3 Answers3

0

Try to format your output text to UTF-8 or ISO-8859-1

Tryliom
  • 111
  • 1
  • 17
0

The original text file must be in UTF-8 otherwise, it will be necessary to convert at the file reading time by:

new String (String_Readed_From_File.getBytes ("ISO-8859-1"), "UTF-8");

If the encoding of the file is ISO-8859-1, otherwise adapt to file's encoding

0

Based on what you're saying, you're trying to read your text file as if it was encoded in UTF-8, but it is not. Therefore, you're failing the initial step of reading the file, and nothing you do afterwards can recover from this failure. It is useless to speak about what to do after reading the file.

We cannot guess what is the real encoding of your initial file. You would need to put this file somewhere for us to download it. All you've shown so far is that it is not in UTF-8 (because if it were, you would not have the problem described.)

You've said that you're using this code:

new String(encoded, "UTF-8");

Because "encoded" contains the bytes of your file, and your file is not in UTF-8, this instruction is wrong. You need to replace "UTF-8" with whatever is the true encoding of your file.

For instance it might be:

new String(encoded, StandardCharsets.ISO_8859_1);

Another solution, would be to not touch your Java code and leave it as-is, but make it correct by making its assumption that the file is in UTF-8, correct. For that you'd use a text editor out there like Notepad++, tell it to convert the file to UTF-8, and save.

kumesana
  • 2,495
  • 1
  • 9
  • 10