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ファイルClose
try {
if (null != zipNotSendFile) {
zipNotSendFile.close();
}
if (null != inStream) {
inStream.close();
}
if (null != zipInStream) {
zipInStream.closeEntry();
}
} catch (IOException e) {
throw e;
}
}
// 戻る
return listCsvFile;
}