javavisual-studio-codeterminalutf-8arabic-support

how to print Arabic text correctly with Java


I try to print Arabic text using Java, like these:

 System.out.println("طباعة نص باللغة العربية");

But the Output (in Terminal):

 ╪╚╟┌╔ غ╒ ╚╟طط█╔ ╟ط┌╤╚و╔

I think the problem on my terminal. Because When I try to type the same text directly in the Terminal, This is how the result looks:

enter image description here

I have tried these encoding: utf-8, utf-8 with Bom and windows1256 , but none of them worked. I am using Visual Studio code version 1.68.1 with JDK 17.0.4 .

I also edited settings.json file as follows:

enter image description here

The purpose is to print the text correctly. So, how can I print the string or content of text correctly in its original form? like:

 طباعة نص باللغة العربية 

Solution

  • The answers and comments above have pointed out that this may be related to the terminal encoding and file encoding format, and have given a valid solution.

    Here are some of my suggestions that may be useful to you:

    Code Runner

    1. Install the Code Runner extension

    2. Use Run Code option to run the code

      enter image description here

    3. Output the results in the OUTPUT panel

      enter image description here

    launch.json

    1. Configure launch.json as follows

       {
           // Use IntelliSense to learn about possible attributes.
           // Hover to view descriptions of existing attributes.
           // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
           "version": "0.2.0",
           "configurations": [
               {
                   "type": "java",
                   "name": "Launch Current File",
                   "request": "launch",
                   "mainClass": "${file}",
                   "console": "internalConsole"
               },
      
           ]
       }
      
    2. Start debugging in the Run and Debug window

      enter image description here

    3. Debug results are displayed in the DEBUG CONSOLE panel

      enter image description here