当我只使用java -Xxx *
时,程序将获取当前路径中的所有内容作为输入。
如何仅获取 *
字符串作为输入?
最佳答案
这不是您在 Java 中所做的任何事情;这是 bash filename expansions 的行为:
After word splitting [...] Bash scans each word for the characters ‘*’, ‘?’, and ‘[’. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern (see Pattern Matching). If no matching filenames are found, and the shell option nullglob is disabled, the word is left unchanged.
正如 Jesper 在评论中指出的那样,您可以通过引用 *
字符来避免这种行为:
java -Xxx '*'
或者,正如 Ilya 所说,你可以逃避它:
java -Xxx \*
关于java - 如何将 "*"解析为 Java 程序作为输入参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43759094/