我需要解析我的主要方法以查看 boolean 值是否设置为 true 或 false,但每次运行它时它都会设置为 false。
当我运行程序时,这是我的交互输出:
> java ScraperTestRunner1 true, "/Desktop/imputfile.txt"
2
false
/Desktop/imputfile.txt
我这个主要方法的代码是:
public static void main(String[] args){
System.out.println(args.length);
if (args.length == 2) {
docketBoolean = Boolean.parseBoolean(args[0]);
inputDateFileString = (args[1]);
System.out.println(docketBoolean);
System.out.println(inputDateFileString);
之前,当我检查 args.length 是否为 1 时,只搜索 boolean 值,它会给我正确的 boolean 值,但现在不是。知道为什么会这样吗?
最佳答案
您正在解析 "true,"
,它与 "true"
不同。
去掉调用中的逗号:
java ScraperTestRunner1 true "/Desktop/imputfile.txt"
命令行参数未指定为逗号分隔列表;它们以空格分隔(使用双引号以允许参数内有空格)。
关于java - 主要方法 parseBoolean 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21997503/