Java CMD 中的“C:\”,文件名、目录名或卷标语法不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18934996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 12:38:54  来源:igfitidea点击:

'C:\' in CMD, the filename, directory name, or volume label syntax is incorrect

javawindowspathcmdjavac

提问by Collin Tinen

Recently started trying to learn java and the first thing I needed to do was to make a PATH variable. My path variable looks like this.

最近开始尝试学习java,我需要做的第一件事就是创建一个PATH变量。我的路径变量看起来像这样。

C:\Users\Collin>echo %path%
'C:\Program Files(x86)\Java\jdk1.7.0_40\bin';C:\Windows;C:\Windows\system32;
'C:\Program Files(x86)\Java\jdk1.7.0_40\bin';C:\Windows;C:\Windows\system32;

So, I attempt to use javac to see if path did work. Javac did not work, showing the error of not recognized as an internal or external command, operable program, or batch file. I then tried just using path and I got this:

所以,我尝试使用 javac 来查看路径是否有效。javac不工作,显示未识别为内部或外部命令、可运行程序或批处理文件的错误。然后我尝试只使用路径,我得到了这个:

C:\Users\Collin>%path%
The filename, directory name, or volume label syntax is incorrect.

I then tried to just use basic explorer paths such as 'C:\' and tried another drive as 'G:\'. I've tried almost every variation of quotations and formatting but nothing seems to work.

然后我尝试只使用基本的资源管理器路径,例如“C:\”,并尝试使用另一个驱动器作为“G:\”。我已经尝试了几乎所有引用和格式的变化,但似乎没有任何效果。

C:\Users\Collin>C:\
'C:\' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Collin>'C:\'
The filename, directory name, or volume label syntax is incorrect.

C:\Users\Collin>"C:\"
'"C:\"' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Collin>'G:\'
The filename, directory name, or volume label syntax is incorrect.

I'm running Windows 7 Ultimate 64-bit as my OS. Will I have to just format my HDD? This seems to be a problem with the registry, and as such I'm thinking that I will have to format and reinstall. But, maybe there is something I didn't catch that you guys can? Any help would be greatly appreciated, even if you tell me I have to format. Thanks in advance.

我正在运行 Windows 7 Ultimate 64 位操作系统。我只需要格式化我的硬盘吗?这似乎是注册表的问题,因此我认为我必须格式化并重新安装。但是,也许有些东西我没有发现你们可以?任何帮助将不胜感激,即使您告诉我我必须格式化。提前致谢。

回答by Jayan

It is not very clear what the problem is. It looks like you installed java to C:\Program Files(x86)\Java\jdk1.7.0_40 and wants to use javac to compile a program.

不是很清楚是什么问题。看起来你把java安装到C:\Program Files(x86)\Java\jdk1.7.0_40,想用javac编译程序。

  • Start cmd
  • set path=C:\Program Files(x86)\Java\jdk1.7.0_40\bin;%path%

  • Create a Java class (HellowWorld.java)

  • Compile using javac HelloWorld.java
  • Run it using java HelloWorld
  • 启动命令
  • 设置路径=C:\Program Files(x86)\Java\jdk1.7.0_40\bin;%path%

  • 创建一个 Java 类 (HellowWorld.java)

  • 使用 javac HelloWorld.java 编译
  • 使用 java HelloWorld 运行它

回答by Endoro

  1. press Windows-key and Pause-key together WinPause
  2. select "Advanced system settings"
  3. in "System Properties" press the button "Environment Variables"
  4. select "Path" in the upper part and press "Edit...":

    enter image description here

  5. append ;%ProgramFiles(x86)%\Java\jdk1.7.0_40\binto the path:

    enter image description here

  6. OK
  1. 同时按下 Windows 键和暂停键 WinPause
  2. 选择“高级系统设置”
  3. 在“系统属性”中按“环境变量”按钮
  4. 选择上半部分的“路径”,然后按“编辑...”:

    在此处输入图片说明

  5. 附加;%ProgramFiles(x86)%\Java\jdk1.7.0_40\bin到路径:

    在此处输入图片说明

  6. OK

回答by mmimis85

Instead of

代替

C:\program files\

C:\程序文件\

put

C:\progra~1\

C:\程序~1\