I want to run a command line programme on Windows, here is the code.
public static String runcmd(String cmd) throws IOException { ProcessBuilder builder = new ProcessBuilder(cmd); builder.redirectErrorStream(true); Process p = builder.start(); BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; StringBuilder sb = new StringBuilder(); while (true) { line = r.readLine(); if (line == null) break; sb.append(line + "%SKIPLINE%"); } System.out.println(sb.toString()); return sb.toString(); }
Everything work fine, except that it prints out the output in Chinese because my Windows language is set to Chinese. Is there any ways to make it output in English?
Advertisement
Answer
Check this link: how to detect operating system language (locale) from java code
What you want to find is a way to temporarily set your locale in the program to English.