java怎样解压缩.CAB格式的文件

dongdongmaster 2007-08-28 05:58:25
.cab格式的文件包中有一个.txt格式的文件,如何用户JAVA代码解压缩出来啊?谢谢!
...全文
360 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cl55 2007-08-28
  • 打赏
  • 举报
回复
com.ms.util.cab

MS以前有这么个包,你看还能不能找到。
cl55 2007-08-28
  • 打赏
  • 举报
回复
try this method.
it accept a relative path to the resource, no matter if its in a cab or not.
something like

getResouece("/package/1.txt");

and return you a DataInputStream.
you can the use the data input stream readLine method to get what you need.



public DataInputStream getResource(String full_resource_name) throws java.io.IOException
{

InputStream is = getClass().getResourceAsStream(full_resource_name);
if(is == null)
throw new IOException("Unable to resolve resource name " + full_resource_name + " (file not found)");

BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buff = new byte[4096];

int len;
byte[] data =null;

while ((len = bis.read(buff)) != -1)
{
baos.write(buff, 0, len);
}

data = baos.toByteArray();
return new DataInputStream(new java.io.ByteArrayInputStream(data));
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧