zip文件解压读取

来源:互联网 发布:知乎 入门游戏键盘 编辑:程序博客网 时间:2024/05/01 02:24

zip解压,并读取里边的文件(CSV文件)


Constants.FILE_PATH_FULL).append(Constants.ZIP_FILE_NAME:zip文件全路径

/** * zipファイル解凍 *  * @param strCsvFileName *            zipファイルに保存したCsvファイル名 * @param * @return List<String> * @throws IOException */public static List<String> getCsvFileList(String strCsvFileName)throws IOException {// 初期化List<String> listCsvFile = new ArrayList<String>();// Zipファイルの中のファイル対象ZipEntry zipEntry;// ファイル読み込み用InputStream inStream = null;ZipInputStream zipInStream = null;// ZipファイルZipFile zipNotSendFile = null;// ZipファイルパスStringBuffer strZipFile = new StringBuffer(Constants.FILE_PATH_FULL).append(Constants.ZIP_FILE_NAME);try {zipNotSendFile = new ZipFile(strZipFile.toString());inStream = new BufferedInputStream(new FileInputStream(strZipFile.toString()));zipInStream = new ZipInputStream(inStream);// Zipファイル解凍while ((zipEntry = zipInStream.getNextEntry()) != null) {if (!zipEntry.isDirectory()&& zipEntry.getName().indexOf(strCsvFileName.replace(".csv", "").replace(".zip", "").substring(0, 6)) >= 0) {// 前日の未到達リストCSV内容を読み込むBufferedReader bufReader = new BufferedReader(new InputStreamReader(zipNotSendFile.getInputStream(zipEntry)));// 前日の未到達リストCSV内容String strCsvline;while ((strCsvline = bufReader.readLine()) != null) {listCsvFile.add(strCsvline);}bufReader.close();}}} catch (IOException e) {throw e;} finally {// 前日の未到達リストCSVのZipファイルClosetry {if (null != zipNotSendFile) {zipNotSendFile.close();}if (null != inStream) {inStream.close();}if (null != zipInStream) {zipInStream.closeEntry();}} catch (IOException e) {throw e;}}// 戻る return listCsvFile;}


0 0
原创粉丝点击