Zipinputstream转file怎么能转换为Fileinputstream转file

当前位置: >
> 如何把InputStream转换成FileInputStream
如何把InputStream转换成FileInputStream
violent_sniper & at
怎么把InputStream转换成FileInputStream?怎么把InputStream转换成FileInputStream?
先用 instanceof 测试一下
violet0925 & &
& & (0)(0)引用
  Java code  InputStream in = // 这里是你已经存在的输入流
FileInputStream fin = // 转换后的文件输入流
// 如果是FileInputStream类型,进行转换
if (in instanceof FileInputStream) {
fin = (FileInputStream)
} else { // 否则,转型失败
throw new Exception();
}violet0024 & &
& & (0)(0)引用
本问题标题:
本问题地址:
温馨提示:本问答中心的任何言论仅代表发言者个人的观点,与希赛网立场无关。请对您的言论负责,遵守中华人民共和国有关法律、法规。如果您的言论违反希赛网问答中心的规则,将会被删除。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&&&湘教QS2-164&&增值电信业务经营许可证湘B2-ZipInputStream怎么读压缩文件啊_java吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:215,107贴子:
ZipInputStream怎么读压缩文件啊收藏
import java.io.Fimport java.io.FileInputSimport java.io.FileOutputSimport java.io.IOEimport java.util.zip.ZipEimport java.util.zip.ZipInputSpublic class ZipStream { public static void main(String[] args) throws IOException {
decompress(); }private static void decompress() throws IOException {ZipInputStream in = new ZipInputStream(new FileInputStream(new File(
"d:/4.zip")));ZipEbyte[] buffer = new byte[1024];try { System.out.println(1);
while ((entry = in.getNextEntry()) != null) {
FileOutputStream out = new FileOutputStream(new File("d:/23",
entry.getName()));
System.out.println(2);
while ((len = in.read(buffer)) & 0) {
out.write(buffer, 0, len);
System.out.println(3);
} finally {
out.close();
}} finally {
in.close();}}}
我这个运行出来entry = in.getNextEntry()好像没有值
求解啊···
登录百度帐号我的游戏推荐游戏
后查看最近玩过的游戏
为兴趣而生,贴吧更懂你。或只需一步,快速开始
扫一扫,访问微社区
查看: 215|回复: 5
ZipInputStream能解压文件夹的文件吗?
黑马币技术分主题
中级黑马, 积分 842, 距离下一级还需 158 积分
中级黑马, 积分 842, 距离下一级还需 158 积分
一下代码可以实现解压带有文件的压缩包,但如果压缩包里面含有文件夹,就无法正常解压了。大家一起来说说怎么样才能把一个具有压缩包的文件全部解压出来呢?
package com.
import java.io.F
import java.io.FileInputS
import java.io.FileOutputS
import java.io.IOE
import java.io.InputS
import java.io.OutputS
import java.util.zip.ZipE
import java.util.zip.ZipE
import java.util.zip.ZipF
import java.util.zip.ZipInputS
* 解压缩文件
* @author Administrator
*/
public class ZipInputStreamTest {
& & & & public static void main(String[] args) throws Exception {
& & & & & & & & // TODO 自动生成的方法存根
& & & & & & & & & & & & File file=new File(&d:&+File.separator+&test.zip&);&&//定义要解压的文件
& & & & & & & & & & & &
& & & & & & & & & & & & File output=
& & & & & & & & & & & &
& & & & & & & & & & & & ZipFile zipFile=new ZipFile(file);& &//得到解压文件
& & & & & & & & & & & & //定义解压缩输入流
& & & & & & & & & & & & ZipInputStream zipInput=new ZipInputStream(new FileInputStream(file));
& & & & & & & & & & & & InputStream input=
& & & & & & & & & & & & OutputStream out=
& & & & & & & & & & & & ZipEntry entry=&&//定义实体类
& & & & & & & & & & & & while((entry=zipInput.getNextEntry())!=null){
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & output=new File(&d:&+File.separator+entry.getName());
& & & & & & & & & & & & & & & & //判断输出文件夹是否存在,如果不存在,则创建文件夹
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & if(!(output.getParentFile().exists())){
& & & & & & & & & & & & & & & & & & & & output.getParentFile().mkdir();
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & //判断输出文件是否存在,如果不存在,则创建该文件
& & & & & & & & & & & & & & & & if(!(output.exists())){
& & & & & & & & & & & & & & & & & & & & output.createNewFile();
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & input=zipFile.getInputStream(entry);
& & & & & & & & & & & & & & & & out=new FileOutputStream(output);
& & & & & & & & & & & & & & & & int b=0;
& & & & & & & & & & & & & & & & while((b=input.read())!=-1){
& & & & & & & & & & & & & & & & & & & & out.write(b);
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & & & & & input.close();
& & & & & & & & & & & & & & & & out.close();
& & & & & & & & & & & & }
& & & & & & & & & & & &
& & & & & & & & & & & &
}
复制代码
黑马币技术分主题
高级黑马, 积分 1485, 距离下一级还需 515 积分
高级黑马, 积分 1485, 距离下一级还需 515 积分
本帖最后由 fantacyleo 于
21:54 编辑
如果压缩包中的某个文件夹非空时,ZipEntry只代表文件,不代表文件夹。你调用ZipEntry的toString方法就知道了。ZipEntry是自带路径的,只需要拿toString输出的字符串去构建File和FileOutputStream就可以了。
财经专业出身的编程爱好者~绝不发水帖,偶尔回复水帖~
黑马币技术分主题
中级黑马, 积分 590, 距离下一级还需 410 积分
中级黑马, 积分 590, 距离下一级还需 410 积分
能&&目测是在做技术分的题目&&今天刚刚做完 正在完善异常处理
黑马币技术分主题
中级黑马, 积分 842, 距离下一级还需 158 积分
中级黑马, 积分 842, 距离下一级还需 158 积分
如果压缩包中的某个文件夹非空时,ZipEntry只代表文件,不代表文件夹。你调用ZipEntry的toString方法就知道 ...
按照你 的方法在尝试
黑马币技术分主题
中级黑马, 积分 842, 距离下一级还需 158 积分
中级黑马, 积分 842, 距离下一级还需 158 积分
能&&目测是在做技术分的题目&&今天刚刚做完 正在完善异常处理
能,应该怎么样呢?可以给个例子参考吗?
黑马币技术分主题
中级黑马, 积分 590, 距离下一级还需 410 积分
中级黑马, 积分 590, 距离下一级还需 410 积分
能,应该怎么样呢?可以给个例子参考吗?
可以&&下次直接联系企鹅吧&&这个不一定实时在线&&12SEVEN5FIVE4NINE396
站长推荐 /2
以梦为马,策马扬鞭,我们要保持奋发竞进的昂扬姿态,保持一股子冲劲、闯劲,不徘徊、不观望,不松气、不泄气,凝心聚力...
史无前例的做到了在中国培训界,第一个敢以班级为单位,不含任何水份,公开所有毕业数据的培训机构!
Powered by
Copyright &当前位置: &
求翻译:at java.util.zip.ZipFile.getInputStream(Unknown Source)是什么意思?
at java.util.zip.ZipFile.getInputStream(Unknown Source)
问题补充:
在java.util.zip.zipfile.getinputstream(来源不明)
在java.util.zip.zipfile.getinputstream(未知源)
在java.util.zip.ZipFile.getInputStream (未知的来源)
在 java.util.zip.ZipFile.getInputStream (未知源)
在 java.util.zip.ZipFile.getInputStream(Unknown Source)
我来回答:
参考资料:
* 验证码:
登录后回答可以获得积分奖励,并可以查看和管理所有的回答。 |
我要翻译和提问
请输入您需要翻译的文本!1227人阅读
1.重建zip包&
新建一个自己的zip包(也就是自己建立一个package),比如com.agile.zip,在这个包中把要用到的类从jdk的源码里放到这里,用eclipse可以很同快地完成这 个工作。需要所类 有:DeflaterOutputStream,InflaterInputStream,ZipConstants,ZipEntry,ZipInputStream,ZipOutputStream
上面这些类在放到com.aigle.zip包中后,在Eclipse中会显示出一些,这里要做得就是更改import以及其它一些工作,惟一的目的就是通过编译,不再出现编译错误。&
2.修改ZipInputStream&
ZipInputStream这个类中,需要修改getUTF8String这个方法,经过试验,用winRar压缩后的zip文件,其中的中文是以gbk编码保存的,因此只需要在这个方法的前面加上&
&&& String s = newString(b,off,len,&gbk&);&
&& } catch (UnsupportedEncodingExceptione) {&
&&& e.printStackTrace();&
修改后的方法类似下面的代码:&
private static String getUTF8String(byte[] b, intoff, int len) {&
&&& String s = newString(b,off,len,&gbk&);&
&& } catch (UnsupportedEncodingExceptione) {&
&&& e.printStackTrace();&
&& // First, count the number ofcharacters in the sequence&
&& int count = 0;&
&& int max = off +&
3.去掉一些本地调用方法&
原来的java.util.zip.ZipEntry里面,要加载本地库,在这里这些代码是没有用处的,去掉就可以了,而如果不去掉,会引起链接错误,很奇怪,这几个native方法我也没有找到在哪儿使用了,sun的jdk1.4.2里留着它们做什么呢?&
&&&&&&& /* loadthe zip library */&
java.security.AccessController.doPrivileged(&
&&& newsun.security.action.LoadLibraryAction(&zip&));&
initIDs();&
然后就大功告成了。哈哈!
详细的代码见csdn的文章
import java.io.F
import java.io.FileInputS
import java.io.FileOutputS
import java.io.IOE
import java.io.InputS
import com.glodon.zip.ZipE
import com.glodon.zip.ZipInputS
import javax.xml.parsers.DocumentB
import javax.xml.parsers.DocumentBuilderF
import org.w3c.dom.D
import org.w3c.dom.E
import org.w3c.dom.N
import org.w3c.dom.NodeL
* 解压ZIP文件
* @author thinkpad
public class TestExtZipFiles {
* 解压含有多个文件的ZIP包
* @param zipFileName
* @param extPlace
private static void extZipFileList(String zipFileName, String extPlace) {
ZipInputStream in = new ZipInputStream(new FileInputStream(zipFileName));
ZipEntry entry =
while ((entry = in.getNextEntry()) != null) {
String entryName = entry.getName().toLowerCase();
if (entryName.endsWith(&.xml&)) {// 找到xml文件
int i = entryName.lastIndexOf(&/&);
entryName = entryName.substring(i+1);
FileOutputStream os = new FileOutputStream(extPlace + entryName);
// Transfer bytes from the ZIP file to the output file
byte[] buf = new byte[1024];
while ((len = in.read(buf)) & 0) {
os.write(buf, 0, len);
os.close();
in.closeEntry();
resolveXMLFile(extPlace + entryName);
File f = new File(extPlace + entryName);
if(f.exists()) {
f.delete();
} catch (IOException e) {
e.printStackTrace();
System.out.println(&解压文件成功 &);
public static void resolveXMLFile(String fileName) {
DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
DocumentBuilder dombuilder = domfac.newDocumentBuilder();
InputStream is = new FileInputStream(fileName);
Document doc = dombuilder.parse(is);
Element root = doc.getDocumentElement();
NodeList bidders = root.getChildNodes();
if(bidders != null){
for(int i=0;i&bidders.getLength();i++){
//一条数据
Node bidder = bidders.item(i);
if(bidder.getNodeType() == Node.ELEMENT_NODE){
String PBRQ = bidder.getAttributes().getNamedItem(&PBRQ&).getNodeValue();
String JHJGSJ = bidder.getAttributes().getNamedItem(&JHJGSJ&).getNodeValue();
String JHKGSJ = bidder.getAttributes().getNamedItem(&JHKGSJ&).getNodeValue();
String ZGZH = bidder.getAttributes().getNamedItem(&ZGZH&).getNodeValue();
String ZLJE = bidder.getAttributes().getNamedItem(&ZLJE&).getNodeValue();
String ZGJ = bidder.getAttributes().getNamedItem(&ZGJ&).getNodeValue();
String XMFBQK = bidder.getAttributes().getNamedItem(&XMFBQK&).getNodeValue();
String ZLBZ = bidder.getAttributes().getNamedItem(&ZLBZ&).getNodeValue();
String AQWMSGF = bidder.getAttributes().getNamedItem(&AQWMSGF&).getNodeValue();
String CSXMF = bidder.getAttributes().getNamedItem(&CSXMF&).getNodeValue();
String XMJLID = bidder.getAttributes().getNamedItem(&XMJLID&).getNodeValue();
String ABBM = bidder.getAttributes().getNamedItem(&ABBM&).getNodeValue();
String TJZB = bidder.getAttributes().getNamedItem(&TJZB&).getNodeValue();
String PM = bidder.getAttributes().getNamedItem(&PM&).getNodeValue();
String FBHJ = bidder.getAttributes().getNamedItem(&FBHJ&).getNodeValue();
String FB = bidder.getAttributes().getNamedItem(&FB&).getNodeValue();
String WXB = bidder.getAttributes().getNamedItem(&WXB&).getNodeValue();
String XMJL = bidder.getAttributes().getNamedItem(&XMJL&).getNodeValue();
String TBBJ = bidder.getAttributes().getNamedItem(&TBBJ&).getNodeValue();
String ZLCN = bidder.getAttributes().getNamedItem(&ZLCN&).getNodeValue();
String GQ = bidder.getAttributes().getNamedItem(&GQ&).getNodeValue();
String Signin = bidder.getAttributes().getNamedItem(&Signin&).getNodeValue();
String BidderName = bidder.getAttributes().getNamedItem(&BidderName&).getNodeValue();
String BidderID = bidder.getAttributes().getNamedItem(&BidderID&).getNodeValue();
String JCDJH = bidder.getAttributes().getNamedItem(&JCDJH&).getNodeValue();
System.out.println(PBRQ+&,&+JHJGSJ+&,&+JHKGSJ+&,&+ZGZH+&,&+ZLJE+&,&+ZGJ+&,&+XMFBQK+&,&+ZLBZ+&,&+AQWMSGF+&,&+CSXMF+&,&+XMJLID+&,&+ABBM+&,&+TJZB+&,&+PM+&,&+FBHJ+&,&+FB+&,&+WXB+&,&+XMJL+&,&+TBBJ+&,&+
ZLCN+&,&+GQ+&,&+Signin+&,&+BidderName+&,&+BidderID+&,&+JCDJH);
} catch (Exception e) {
e.printStackTrace();
* @param args
public static void main(String[] args) {
//zip的文件位置,和解压之后的xml的位置
extZipFileList(&E:\\1010111_BHWJ.zip&,&E:\\1010111\\&);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:55144次
积分:1406
积分:1406
排名:第12895名
原创:89篇
评论:20条
(1)(2)(2)(4)(2)(1)(5)(10)(7)(2)(17)(45)}

我要回帖

更多关于 怎么能长高 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信