首页 > 解决方案 > How to save a single .java file from eclipse

问题描述

I'm trying to save a single class file as a .java file from Eclipse. I've tried right clicking on the class, exporting as a JAR file and save to my desktop, but when I open it, it is just a bunch of weird symbols. How do I just export a single .java file??? Help please!

标签: javaeclipse

解决方案


只需将文件从 Eclipse 文件浏览器拖放到桌面即可。

或者

只需从 .java 文件中复制代码完整代码,然后使用文件资源管理器在任意位置创建一个新的文本文件,并将内容粘贴到其中并保存。然后将其重命名为 Filename.java

在这里,您应该从设置中打开显示文件扩展名,否则我认为您将无法更改扩展名。

然后您可以通过以下方式编译文件:

javac Filename.java

并运行:

java MainClass

并通过以下方式创建 JAR:

jar cfve file.jar Main Main.class

推荐阅读