有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在Windows 2008 R2德语区域设置中,unicode附加的java代码无法在输出中正确打印德语字符

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;



public class ping1 {

    /**
     * @param args
     */
    public static String feedback = "";

    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Add the ubiquitous "Hello World" label.
        JTextArea ta = new JTextArea(feedback);
        frame.getContentPane().add(ta);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("Test1");
        Runtime rTime = Runtime.getRuntime();
        Process p;


        try{
            p = rTime.exec("ping 10.11.11.67");
            InputStream stdout = p.getInputStream();
            InputStream stderr = p.getErrorStream();

            BufferedReader reader = new BufferedReader(new InputStreamReader(stdout,"UTF-8"));
            StringBuffer data = new StringBuffer();
            String line = "";

            char sch = 13;  // check for ^M character
            char dch = '\n';    // replace ^m by next line character

            while (line != null) { 
                line = reader.readLine();

                if (line != null){

                    line = new String(line.getBytes(),"UTF-8");
                    //System.out.println("line after :"+line);
                    data.append(line.replace(sch, dch));        // 7.1.00 AMTRAK QM001531720
                }       
                data.append(System.getProperty("line.separator"));
            }
            // notify listeners if feedback is not suppressed
            ping1.feedback = data.toString();

            System.out.println("Data in feebback:"+ping1.feedback.toString());


//            System.out.println("Output stream:"+strout );
//            System.out.println("Error stream:"+strerr );

        }
        catch(IOException npe){
            System.out.println(npe.getMessage());
            return;
        }

        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });


    }

}

我需要的输出应该与此框上提供的ping命令完全相同,而不是它为我提供的输出? 例如,命令窗口上ping的输出以 Ping wird ausgeführt für 10.11.11.67 mit 32字节日期:

但是当我从代码中运行这个时

你是谁?HRTF?r 10.11.11.67 mit 32字节日期:

检查für和f?r


共 (1) 个答案

  1. # 1 楼答案

    可能是jvm编码导致了这个问题。尝试设置环境变量(计算机->;属性->;高级系统设置->;新变量)

    变量名称:JAVA_工具_选项
    变量值:-d文件。编码=UTF8