Problems with shrugging ascii emoji ¯ \ _ (ツ) _ / ¯ in plain text with java

I am developing a java program that writes output to a text file. When something goes wrong, I have to put this ASCII art:

¯\_(ツ)_/¯ 

I did this using this BufferedOutputStream :

 errorOutput.writeln("##################################\n" + "##### Error Output ######\n" + "##### ¯\\_(ツ)_/¯ ######\n" + "##################################\n"); 

The problem is that when I see the txt log associated with java, I get the following:

 ################################## ##### Error Output ###### ##### ¯\_(ツ)_/¯ ###### ################################## 

How can I write the correct AOSII emoji in Java?

+5
source share
3 answers

Solved with these code snippets:

  @GET @Path("getStdErr/{idApp}") @Produces("text/html; charset=UTF-8") public Response getStdErr(@PathParam("idApp") Integer idApp) { return super.getStderr(jobsMap.get(idApp)); } 

. ,,.

 return Response.ok(job.getStdErr(), "text/plain; charset=UTF-8").build(); 
0
source

Saving the .java file as UTF-8 , this code works for me:

 String string = "##################################\n" + "##### Error Output ######\n" + "##### ¯\\_(ツ)_/¯ ######\n" + "##################################\n"; Charset.forName("UTF-8").encode(string); System.out.println(string); 

OUTPUT:

 ################################## ##### Error Output ###### ##### ¯\_(ツ)_/¯ ###### ################################## 

DEMO HERE .

+4
source

The file is in UTF-8, but you are viewing it in single-byte encoding:

  • You see UTF-8 multibyte sequences for special characters with char for each byte.

Make sure you read it as UTF-8, because you really use non-ASCII, comma, quotation marks, and Japanese. So UTF-8 is fine.

Windows dirty trick:

 String string = "\uFEFF##... 

This writes the Unicode char specification, which, being the first char of a file, is interpreted as a Unicode token.

Otherwise, create an HTML file with the specified encoding:

 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head> <body><pre>...</pre></body></html> 

Display on the System.out console is not possible on a system other than UTF-8, such as Windows.

Also, so that your application is portable, make sure that you specify the encoding for the record; it is often an optional argument, with an overridden method / constructor.

+2
source

All Articles