我通过 VScode 运行以下代码。不是 CMD 或 PowerShell,我也没有使用 VScode 的终端部分。我只是通过 VScode 打开文件并运行它们,我得到了以下每个输出
所以这就是发生的事情我正在运行保存在
c 中的代码
public class Test {
public static void main(String[] args) {
System.out.println("this is working");
}
}
保存在 c 中的文件的输出
Running] cd "c:\lec c\" && javac Test.java && java Test
this is working
[Done] exited with code=0 in 3.176 seconds
我正在运行保存在d中的代码
public class Test {
public static void main(String[] args) {
System.out.println("this is working");
}
}
保存在d中的文件的输出
[Running] cd "d:\lec d\" && javac Test.java && java Test
error: file not found: Test.java
Usage: javac <options> <source files>
use --help for a list of possible options
[Done] exited with code=2 in 0.593 seconds
我正在运行保存在 e 中的代码
public class Test {
public static void main(String[] args) {
System.out.println("this is working");
}
}
保存在 e 中的文件的输出
[Running] cd "e:\lec e\" && javac Test.java && java Test
error: file not found: Test.java
Usage: javac <options> <source files>
use --help for a list of possible options
[Done] exited with code=2 in 0.532 seconds
我想知道为什么保存在“d”和“e”中的文件会发生这种情况。我知道的一点是原因可能与环境变量有关,但对我来说还不够清楚。有人可以向我解释一下确切的原因吗? 感谢您的时间和精力。
如果您从 cmd 提示符运行,请使用
cd /d
。如果您只使用
cd
,它会保留在您所在的任何驱动器上。