在Java中将系统属性设置为Null [英] Set System propery to Null in Java

查看:575
本文介绍了在Java中将系统属性设置为Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单元测试中,我需要将"workingDir"系统属性设置为Null.

In my unit tests I need to set the "workingDir" system property to Null.

但是我不能做这样的事情,因为它给了我NullPointerException:

But I can not do somesing like this, because It give me NullPointerException:

System.setProperty("workingDir", null);

我该怎么办?

推荐答案

您不能将属性设置为具有实际的空值-您只能清除它,如下所示:

You can't set a property to have an actual null value - you can only clear it, like this:

System.clearProperty("workingDir");

这篇关于在Java中将系统属性设置为Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆