采用ZipInputStream解压zip格式的文件,遇到一个问题。。。。。 ZipInputStream zipIsStream = new ZipInputStream(new FileInputStream(filename));我想问一下,在正在解压的过程中,如果解压文件不存在了,这个时候会出现什么问题???我目前遇到的就是:正在解压文件,但是这个文件已经不存在了(就是强制卸载掉文件,这个文件在u盘上,把U盘拔掉),只能解压出文件中部分文件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你贴个方法我自己的代码 /*此方法用于测试*/ public boolean zip(File infile, File osfile) throws IOException { FileInputStream in = null; ZipOutputStream os = null; try { os = new ZipOutputStream(new FileOutputStream(osfile)); File[] fs = infile.listFiles(); for (int i = 0, count = fs.length; i < count; i++) { in = new FileInputStream(fs[i]); os.putNextEntry(new org.apache.tools.zip.ZipEntry(fs[i].getName())); byte[] b = new byte[2048]; int len; while ((len = in.read(b)) > 0) { os.write(b, 0, len); } os.flush(); os.closeEntry(); in.close(); } } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { in.close(); } if (os != null) { os.close(); } } return true; } public static void main(String[] args) { Queryfileinfo m_zip = new Queryfileinfo(); try { m_zip.zip(new File("D:\\tomcatoracle\\webapps\\yqoa\\download"), new File("D:\\a.zip")); } catch (Exception ex) { ex.printStackTrace(); }}需要一个包,ant.jar while ((z = in.getNextEntry()) != null) { if (z.getName().equals(getNoChooseModules(mNeededChangeList, z.getName()))) { continue; } if (!z.isDirectory()) { File f = new File(ThemeConstants.mUnzipPath+ z.getName()); File themefilepath = new File(ThemeConstants.mUnzipPath); if (themefilepath.exists()) { Log.d(TAG, "themefilepath is exists"); } else { String command1 = "/system/bin/mkdir /data/THEME"; Runtime runtime1 = Runtime.getRuntime(); try { runtime1.exec(command1); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { boolean tempBe = f.createNewFile(); if(tempBe == false) } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); ThemeManagerApplication.getInstance().exit(); return; } FileOutputStream out = new FileOutputStream(f); int b; byte[] buffer = new byte[4096]; while ((b = in.read(buffer)) > 0) out.write(buffer, 0, b); out.close(); //貌似,我没像你的那样刷新缓冲,判断空指针的问题应该不存在,如果是空指针,log信息会报错,现在就是,当我解压文件的,解压的一半的时候,我把文件搞掉,就是文件是手机SD卡中的,解压到一半,我把手机USB模式调成 :打开存储功能,这个时候,手机上的软件正在解压手机SD卡中的文件,手机的USB却是连接到了电脑上,软件就找不到正在解压到文件了,这样会不会导致手机死掉? in.close();} 学习接口实现,编译出错,请高手指点 关于对象的周期 从内存块中调用类 排序怎么这么难啊!!??请教高手 为什么String str1 = "abc";String str2= "abc";中的str1和str2是相同的? eclipse如何打开已有的工程(eclipse的) 今天正式加盟Java!请教java.lang中Import的类位置. 请教 求swt 遍历 Tree的例子 关于字体问题 关于Java中的String对象中的堆与栈的问题 Java当中的Array和Arrays的区别到底是什么?
public boolean zip(File infile, File osfile) throws IOException {
FileInputStream in = null;
ZipOutputStream os = null;
try {
os = new ZipOutputStream(new FileOutputStream(osfile));
File[] fs = infile.listFiles();
for (int i = 0, count = fs.length; i < count; i++) {
in = new FileInputStream(fs[i]);
os.putNextEntry(new org.apache.tools.zip.ZipEntry(fs[i].getName()));
byte[] b = new byte[2048];
int len;
while ((len = in.read(b)) > 0) {
os.write(b, 0, len);
}
os.flush();
os.closeEntry();
in.close();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
in.close();
}
if (os != null) {
os.close();
}
} return true;
} public static void main(String[] args) {
Queryfileinfo m_zip = new Queryfileinfo();
try {
m_zip.zip(new File("D:\\tomcatoracle\\webapps\\yqoa\\download"), new File("D:\\a.zip"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
需要一个包,ant.jar
{
if (z.getName().equals(getNoChooseModules(mNeededChangeList, z.getName())))
{
continue;
}
if (!z.isDirectory())
{
File f = new File(ThemeConstants.mUnzipPath+ z.getName());
File themefilepath = new File(ThemeConstants.mUnzipPath);
if (themefilepath.exists())
{
Log.d(TAG, "themefilepath is exists");
}
else
{
String command1 = "/system/bin/mkdir /data/THEME";
Runtime runtime1 = Runtime.getRuntime();
try
{
runtime1.exec(command1);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try
{
boolean tempBe = f.createNewFile();
if(tempBe == false)
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
ThemeManagerApplication.getInstance().exit();
return; }
FileOutputStream out = new FileOutputStream(f);
int b;
byte[] buffer = new byte[4096];
while ((b = in.read(buffer)) > 0)
out.write(buffer, 0, b);
out.close();
//貌似,我没像你的那样刷新缓冲,判断空指针的问题应该不存在,如果是空指针,log信息会报错,现在就是,当我解压文件的,解压的一半的时候,我把文件搞掉,就是文件是手机SD卡中的,
解压到一半,我把手机USB模式调成 :打开存储功能,这个时候,手机上的软件正在解压手机SD卡中的文件,手机的USB却是连接到了电脑上,软件就找不到正在解压到文件了,这样会不会导致手机死掉?
in.close();
}