同样一段java代码,在eclipse的run模式与debug模式为什么结果会不一致??

本文探讨了一段Java代码在不同IDE环境下获取Windows系统环境变量的行为差异。具体表现为,在Eclipse IDE中Debug模式下,所有环境变量名被转换为大写,而在Run模式和其他IDE如IntelliJ IDEA中则正常显示大小写。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.aking.test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;

public class TestEnv {
public static Properties getEnvVars() throws Throwable {
Process p = null;
Properties envVars = new Properties();
Runtime r = Runtime.getRuntime();
String OS = System.getProperty("os.name").toLowerCase();
// System.out.println(OS);
if (OS.indexOf("windows 9") > -1) {
p = r.exec("command.com /c set");
} else if (OS.indexOf("windows") > -1) {
// thanks to JuanFran for the xp fix!
p = r.exec("cmd.exe /c set");
} else {
// our last hope, we assume Unix (thanks to H. Ware for the fix)
p = r.exec("env");
}

BufferedReader br = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
int idx = line.indexOf('=');
String key = line.substring(0, idx);
String value = line.substring(idx + 1);
envVars.setProperty(key, value);
System.out.println(line);
}
return envVars;
}

public static void main(String args[]) {
try {
Properties p = TestEnv.getEnvVars();
System.out.println("the current value of TEMP is : "
+ p.getProperty("TEMP"));
} catch (Throwable e) {
e.printStackTrace();
}
}
}

就这么一段代码,获取widows系统的环境变量,为什么debug模式下的结果与run模式下的结果会不一样呢?在run模式下是正常的,大小写区分的。但是在debug模式下,环境变量名称全成了大写???

在IntelliJ IDEA环境下验证同样的代码,run模式和debug模式得到的结果是一致的。因此推断,应该是eclipseIDE debug插件的问题。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值