java调用cmd命令中文乱码解决方案

直接使用输出为乱码

Process proc;
        try {
            proc = Runtime.getRuntime().exec("ipconfig");
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream());
            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            proc.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } 

改进,添加第二参数为GBK

Process proc;
        try {
            proc = Runtime.getRuntime().exec("ipconfig");
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(),"GBK"));
            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            proc.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } 
上一篇:Android binder学习笔记4 - binder transact流程分析


下一篇:虚拟文件系统 sys、proc