The real problem in your code is that you do not know what real encoding of files is. When you read a line from a web service, you get a sequence of characters; when converting a string from characters to bytes, the conversion is performed correctly, since you specify how to convert char to bytes with a specific encoding ("UFT-8"). when you read a text file, you are faced with another problem. You have a sequence of bytes that need to be converted to characters. To do this correctly, you must know how characters that are converted to bytes, that is, what is the encoding of the file. For files (if not specified), these are platform constants; on windows, the file is encoded in win1252 (which is very close to ISO-8859-1); on linux / unix it depends, I think, UTF8 by default.
By the way, a web service call did an escrow operation under the hood; The HTTP call uses the taht header, which determines how characters are encoded, i.e. how to read bytes from a socket and then convert them to characters. Therefore, calling the SOAP web service returns xml (which can be connected to a Java object), and all encoding operations are performed correctly.
So, if you must read the characters from a file, you must encounter a coding problem; you can use BASE64, as you stated, but lose one of the main advantages of text files: they are readable, easier to debug and develop.
source share