1. 程式人生 > >java執行cmd命令,返回結果中文亂碼問題解決

java執行cmd命令,返回結果中文亂碼問題解決

public static void main(String[] args) {
		try {
			// 執行ping命令
			Process process = Runtime.getRuntime().exec("cmd /c e:&dir");
			BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream(), Charset.forName("GBK")));
			String line = null;
			while ((line = br.readLine()) != null) {
				System.out.println(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

http://blog.csdn.net/fabuler/article/details/46879819