Reputation: 982
what I wanna do is read the Windows environment variable %APPDATA%. I have some severe problems with Umlauts though e.g. if APDATA is set to "ÄÄÄ"
I ll get sth like "'''"
.
Here is my code:
final Process p = Runtime.getRuntime().exec("cmd.exe /C echo %APPDATA%");
final BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String buffer;
if((buffer = br.readLine()) != null) {
return buffer;
}
If I print out
String encoding_system = System.getProperty("file.encoding");
I'm getting Cp1252
. I tried to tell the InputStreamReader the system encoding, but nothing changes.
Upvotes: 0
Views: 1854
Reputation: 12009
That's a brittle way of trying to get an environment variable's value. You're better off using System.getEnv()
. This will return a Map<String, String>
instance linking environment variable names to their values.
Upvotes: 1