简体   繁体   English

为什么我不能在命令行中运行 .java 文件?

[英]Why I can't run a .java file in the command line?

I'm trying to run this in the command line: java InOut There is a file InOut.java there, I can see it when I run the dir command.我试图在命令行中运行它: java InOut 那里有一个文件 InOut.java,当我运行 dir 命令时我可以看到它。 But I always get "Could not find or load main class InOut".但我总是得到“无法找到或加载主类 InOut”。 What am I doing wrong?我究竟做错了什么? I'm using Eclipse by the way.顺便说一下,我正在使用 Eclipse。

Thanks谢谢

Before you can run Java code, it must be compiled.在运行 Java 代码之前,必须对其进行编译。 Run the command javac InOut.java and then run java InOut .运行命令javac InOut.java ,然后运行java InOut

Eclipse will automatically compile your saved Java files for you, so you don't actually need to do it on the command line. Eclipse 会自动为您编译保存的 Java 文件,因此您实际上不需要在命令行上执行此操作。 When running your programs in command line, you have to go to the bin folder, not the src folder.在命令行中运行程序时,您必须转到 bin 文件夹,而不是 src 文件夹。 There, you should find InOut.class, and be able to run it.在那里,您应该找到 InOut.class,并且能够运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM