读取ear,jar压缩包里面的文件。
来源:互联网 发布:苹果通过usb共享网络 编辑:程序博客网 时间:2024/06/15 20:46
今天写ComFrame属性配置工具,参照网上的资料,实现了题目的功能。
支持原创啊。
这里的流程是这样的。层层剥皮。
//------------------
读取jar文件里面的文件
//----------------
import java.io.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class ReadFileImpl implements IReadFile{
public String readFile() {
String result = "";
try {
String currentJarPath = ReadFileImpl.class.getProtectionDomain().getCodeSource().getLocation().getFile();
JarFile currentJar = new JarFile("conf.jar");
JarEntry dbEntry = currentJar.getJarEntry("text.properties");
InputStream in = currentJar.getInputStream(dbEntry);
//FileInputStream fis = new FileInputStream(currentJarPath+"/text.properties");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String readLine = null;
while((readLine = br.readLine())!= null){
result = result + readLine;
}
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return result;
}
}
//----------------------
解压某个文件 把conf.jar从UWFE.ear里面解压出来
//---------------------
JarFile currentJar = new JarFile(path + "/UWFE.ear");
JarEntry dbEntry = currentJar.getJarEntry("conf.jar");
InputStream in = currentJar.getInputStream(dbEntry);
FileOutputStream fos = new FileOutputStream(path+"/conff.jar", true);
int i = 0;
while ((i = in.read()) != -1) {
fos.write(i);
}
fos.flush();
fos.close();
//------------------------
打包 把conf.jar打包到UWFE.ear里面。
//------------------------
private static boolean EAR(){
try {
File tempJar = new File(filepath+"/UWFE1.ear");
tempJar.createNewFile();
JarFile jar = new JarFile(filepath+"/UWFE.ear");
FileOutputStream f = new FileOutputStream(tempJar);
JarOutputStream newJar = new JarOutputStream( f);
byte buffer[] = new byte[100];
int bytesRead;
// Add back the original files
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
// Prompt for copy
JarEntry entry = (JarEntry) entries.nextElement();
if(entry.toString().equals("conf.jar"))
continue;
InputStream is = jar.getInputStream(entry);
newJar.putNextEntry(entry);
while ((bytesRead = is.read(buffer)) != -1) {
newJar.write(buffer, 0, bytesRead);
}
newJar.flush();
is.close();
} // Add new file last
jar.close();
JarEntry entry = new JarEntry("conf.jar");
newJar.putNextEntry(entry);
FileInputStream fis = new FileInputStream(filepath+"/conf.jar");
while ((bytesRead = fis.read(buffer)) != -1) {
newJar.write(buffer, 0, bytesRead);
}
newJar.flush();
fis.close();
newJar.close();
f.close();
return true;
} catch (Exception ex){
ex.getMessage();
return false;
}
}
如果需要转载,请标明出处,尊重偶的原创版权啊。
http://www.chinacsharp.net
http://blog.csdn.net/keyboardsun
作者keyboardsun
- 读取ear,jar压缩包里面的文件。
- 如何读取Jar包里面的文件
- 如何读取Jar包里面的文件
- 运行jar包时读取jar里面的文件
- EAR、JAR文件的读写
- jar 包的认识与处理、jar 文件 war 文件以及 ear 文件
- jar,war,ear包的区别
- .jar/war/ear包的区别
- jar/war/ear包的区别
- JAR WAR EAR包的区别
- .jar/war/ear包的区别
- .jar/war/ear包的区别
- 修改jar包里面的class文件
- 解决jar包里面的文件冲突
- jar\war\ear包
- jar、ear、war包
- Java的JAR包, EAR包 ,WAR包
- Java的JAR包, EAR包 ,WAR包内部结构
- 经典正则表达式
- 解析Oracle数据库中配置文件
- Flash Remoting For .Net 的跨域连接问题解决~
- java图像界面开发简单实例-JOptionPane应用
- oralce10g数据库连接失败
- 读取ear,jar压缩包里面的文件。
- SQL*Loader使用指南
- 兼容IE、FF的多级菜单(需配合JQuery使用)
- javascript取得地址栏参数
- 在Oracle中如何利用Rowid查找和删除表中的重复记录
- [英语阅读]生而为赢—新东方英语背诵美文(27)-An October Sunrise 十月的日出
- Vector、ArrayList、List使用深入剖析
- csdn的第一篇文章
- [英语阅读]生而为赢—新东方英语背诵美文(28)-To Be or Not to Be 生存还是毁灭