【class2src】Decompiler
方法源自:https://stackoverflow.com/questions/272535/how-do-i-decompile-java-class-files
功能:给定一个.class文件,得到反编译的源码。
下载后导入工具包:Procyon (https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler)
Demo:
package util;
import java.io.StringWriter;
public class Decompile {
public void main(String[] args) {
String classPath = “*.class”; //input path of .class file
String src = class2src(classPath);
System.out.println(src);
}
public String class2src(String classPath) {
final StringWriter writer = new StringWriter();
String src = "";
try {
com.strobel.decompiler.Decompiler.decompile(classPath, new com.strobel.decompiler.PlainTextOutput(writer));
} catch (IllegalArgumentException e) {
System.out.println("classpath : " + classPath);
} finally {
src = writer.toString();
}
return src;
}
}
If you have any questions about this article, welcome to leave a message on the message board.
Brad(Bowen) Xu
E-Mail : maxxbw1992@gmail.com

浙公网安备 33010602011771号