从jar中取出指定的文件
2004-09-27 09:24
274 查看
import java.io.*; import java.util.jar.*; import java.util.zip.*; public class ExtractFromJAR { public void extractMyDBFromJAR(String dest){ try { String home = getClass().getProtectionDomain(). getCodeSource().getLocation().toString(). substring(6); JarFile jar = new JarFile(home); ZipEntry entry = jar.getEntry("mydb.mdb"); File efile = new File(dest, entry.getName()); InputStream in = new BufferedInputStream(jar.getInputStream(entry)); OutputStream out = new BufferedOutputStream(new FileOutputStream(efile)); byte[] buffer = new byte[2048]; for (;;) { int nBytes = in.read(buffer); if (nBytes <= 0) break; out.write(buffer, 0, nBytes); } out.flush(); out.close(); in.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String args []){ new ExtractFromJAR().extractMyDBFromJAR("."); } } |
java -jar mydb.jar |
相关文章推荐
- Java连接数据库+连续读取文件夹下txt文件+读取出txt文件后字符串简单分割连接处理+导入jar包
- .bat文件打开指定网页,并运行jar包
- Springboot jar包外指定配置文件及原理
- java中使用sfntly的sfnttool.jar 抽取指定中文字符串ttf文件,简化、裁剪ttf字体库文件大小,java缩小中文ttf字体库文件大小
- Eclipse 打jar包,并且在win7 下执行jar文件,MANIFEST.MF文件指定执行入口
- Java 遍历文件夹 取出指定文件格式的文件
- Android编译jar和指定目标文件
- maven打包排除排除指定文件(war,jar)
- java基于jxl.jar包生成Excel文件到指定目录和服务器下载两种模式的使用方法
- mkdir javac jar clean 在控制台或者MyEclipse指定project的,而不是在构建文件<project name="OurProject" default="archive"
- svn命令行取出文件副本至本地指定目录
- java使用poi把从数据库中取出的数据写入到excel文件中并保存到指定文件路径
- Android开发随手记录-AS导出jar包 Android Studio生成包含assets的Jar 从Eclipse迁移到Android Studio,并打包指定文件到jar
- (tomcat中级)应用Tomcat的WebappClassLoader加载指定目录的jar文件
- pom文件中使用指定路径的方式配置jar包依赖
- 简单将指定文件打包成jar包
- 遍历ZIP(JAR)文件,动态加载,找出其中指定类型的类
- 如何在weblogic启动时让其加载指定的jar库文件
- 总结替换jar包中指定文件的步骤
- 扫描指定包(包括jar)下的class文件