如何将所有类的文件扩展名从.class还原为.java?

huangapple go评论55阅读模式
英文:

How to revert the file extension of all classes from .class to .java?

问题

我正在使用Eclipse IDE和GitBash开发一个Java汽车共享控制台应用程序。在使用GitBash时,我不小心将项目中所有的类从.java扩展名更改为.class扩展名。现在,当我尝试在Eclipse中打开这些类时,它们不被识别为Java类,无法进行编译。有没有办法将所有类的文件扩展名恢复为.java?

我尝试过手动将它们改回来,但没有成功。

文件

当我展开类和展开java时,没有任何变化。

如何将所有类的文件扩展名从.class还原为.java?

英文:

I am working on a Java carsharing console application using Eclipse IDE and GitBash. While working with GitBash, I accidentally renamed all the classes in my project from having a .java extension to having a .class extension. Now, when I try to open the classes in Eclipse, they are not recognized as Java classes and cannot be compiled. Is there a way to revert the file extension of all the classes back to .java in my project?
I tried to rename them back to manual but it didn't work.
files

I tried to rename them back to manual but it didn't work.
[when expanding the class and when expanding the java, nothing has changed] 如何将所有类的文件扩展名从.class还原为.java?

答案1

得分: 2

根据现有的信息,似乎您没有重命名文件,实际上是将它们编译成了 .class 文件。如果您丢失了源代码,您可以尝试使用 Java 反编译器进行恢复,它可以执行与 Java 编译器相反的操作。它可以尝试从 .class 文件创建相应的源代码。请注意,反编译器的工作是近似的,有时它无法完全重构原始代码,或者可能会丢失一些细节。格式和注释在反编译时总是会丢失的。

英文:

Based on the information available it seems that you didn't rename the files, you actually compiled them to .class files. If you lost your source code you can try to recover it by using a Java Decompiler, which does the reverse that the Java compiler. From .class files it can try to create the equivalent source Java. Note that a decompiler does an approximate work and sometime it can not reconstruct the original, or may loose some details. Formatting and comments are always lost when decompiling.

huangapple
  • 本文由 发表于 2023年5月6日 20:13:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76188828.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定