Sur*_*yaa 4 java file-io jar class
我想读取.class位于.jar包内的文件.如何.class从.jar包中读取可读文件?
我的环境是:
JavaJava 1.8.0_73Java(TM) SE Runtime Environment (build 1.8.0_73-b02)Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)Windows 10 Home (64-bit) [build 10586]编辑:
我提取的.class文件包含二进制和编译的字节码:
我想要的输出:
使用反编译器.我更喜欢使用Fernflower,或者如果你使用IntelliJ IDEA,只需打开那里的.class文件,因为它预装了Fernflower.
或者,转到javadecompilers.com,上传.jar文件,使用CFR并下载反编译的.zip文件.
但是,在某些情况下,反编译代码是非常非法的,所以,更喜欢学习而不是反编译.
小智 5
.zip以编程方式提取/.jar文件的内容假设.jarfile是要提取的.jar/文件。是将其提取的路径:.zipdestDir
java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
java.util.Enumeration enum = jar.entries();
while (enum.hasMoreElements()) {
java.util.jar.JarEntry file = (java.util.jar.JarEntry) enum.nextElement();
java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName());
if (file.isDirectory()) { // if its a directory, create it
f.mkdir();
continue;
}
java.io.InputStream is = jar.getInputStream(file); // get the input stream
java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
while (is.available() > 0) { // write contents of 'is' to 'fos'
fos.write(is.read());
}
fos.close();
is.close();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9227 次 |
| 最近记录: |