Google App Engine Encoding

I am trying to write some kind of Russian text:

LOG.info(" "); 

But instead, I get question marks (browsing from the Internet):

[application identifier / application version] .: 15: 18: 44,753 INFO [class] - ????????????????????

Java file saved with UTF-8 encoding. All default settings.

Even I read a file in UTF-8 with Russian characters and try to write something from it - the encoding is also wrong.

+4
source share
2 answers

I had a similar problem with Hebrew text. I found out that this was caused by the default encoding.

To check the default encoding, I used this code:

 OutputStreamWriter out = new OutputStreamWriter(new ByteArrayOutputStream()); String encoding = out.getEncoding(); 

On my computer, the encoding is "UTF8". On the GAE server, this is "ASCII".

I solved the problem by replacing all the file readers in my code:

 new InputStreamReader(new FileInputStream(file), "UTF8")); 

This tells Java to ignore the default encoding and opens all input files as UTF8.

+3
source

Try it. GAE seems to be trying to auto-detect the encoding and fails. Even the constant lines were ruined

 public class Util { public static String FixRussianString(String string){ try { return new String(string.getBytes("CP1251"), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return string; } } 
+1
source

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


All Articles