当前位置: 代码迷 >> J2EE >> rar文件怎么读出转换成byte[]
  详细解决方案

rar文件怎么读出转换成byte[]

热度:389   发布时间:2016-04-22 03:25:24.0
rar文件如何读出转换成byte[]?
现在有个rar的压缩包文件,想把它读出来转成一个byte[],应该如何写这个代码?谢谢!

------解决方案--------------------
先解压
Java code
public static List unzip(FormFile formFile) {        if (formFile == null)            return null;        List list = null;        InputStream in = null;        ZipInputStream zipInput = null;        try {            in = formFile.getInputStream();            zipInput = new ZipInputStream(in);            ZipEntry zipEntry = null;            list = new ArrayList();            while ((zipEntry = zipInput.getNextEntry()) != null) {                if (!zipEntry.isDirectory()) {                    FileBean fb = new FileBean();                    int len = new Long(zipEntry.getSize()).intValue();                    byte[] data = new byte[len];                    int actual = 0;                    int bytesread = 0;                    while ((bytesread != len) && (actual != -1)) {                        actual = zipInput                                .read(data, bytesread, len - bytesread);                        bytesread += actual;                    }                    fb.setFileSize(len);                    fb.setFileName(zipEntry.getName());                    fb.setFileType(zipEntry.getName().substring(                            zipEntry.getName().lastIndexOf(".") + 1));                    fb.setContents(data);                    fb.setUploadDate(DateTimeUtil.getToDate());                    fb.setUploadTime(DateTimeUtil.getToSecond());                    list.add(fb);                }            }        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        } finally {            try {                if (zipInput != null) {                    zipInput.close();                }                if (in != null) {                    in.close();                }            } catch (Exception ex) {            }        }        return list;    }
  相关解决方案