日期:2014-05-16  浏览次数:20510 次

一个简单的解压ZIP Excl文件--->按时间读取Excle文件,通过Fat jar打成jar相对应的添加到mysql数据库中。
写道
一个简单的解压ZIP Excl文件--->按时间读取Excle文件,通过Fat jar打成jar相对应的添加到mysql数据库中。
package common.gaoyang;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

/**
?* 文件的读写
?*
?* @author liming
?*
?*/
public class CardZipFileOperating {
??? private static final Logger logger = LoggerFactory.getLogger(CardZipFileOperating.class);
//??? // 解压到的目标文件
//??? public static String directory = "E:\\demo\\";
//??? // 解压文件
//??? public static String stringg = "F:\\缴费网\\DL20111213003195.zip";

??? /**
??? ?* 解压,处理下载的zip工具包文件
??? ?*
??? ?* @param directory
??? ?*??????????? 要解压到的目录
??? ?* @param string
??? ?*??????????? 工具包文件
??? ?* @throws IOException
??? ?* @throws Exception
??? ?*???????????? 操作失败时抛出异常
??? ?*/
??? public static int unzipFile(String directory,String stringg) throws IOException{
??? ??? ZipInputStream zis=null;
??? ??? int f=0;
??? ??? try {
??? ??? ??? zis = new ZipInputStream(new FileInputStream(stringg));
??? ??? } catch (Exception e) {
??? ??? ??? f++;
??? ??? ??? System.out.println("解压ZIP文件失败!");
??? ??? ??? System.out.println("没有找到"+stringg+"目录下文件,检查下是不是文件的路径格式写的不对,如:D盘下的DL202111213003195.zip文件格式写成:D:\\"+"\\DL202111213003195.zip");
??? ??? }
??? ?if(zis!=null){
??? ??? ZipEntry ze = null;
??? ??? try {
??? ??? ??? ze = zis.getNextEntry();
??? ??? } catch (IOException e) {
??? ??? ??? // TODO Auto-generated catch block
??? ??? ??? f++;
??? ??? ??? e.printStackTrace();
??? ??? }
??? ??? File parent = new File(directory);
??? ??? if (!parent.exists() && !parent.mkdirs()) {
??? ??? ??? System.out.println("创建给文件解压到那个 \"" + directory+ "\"目录 失败");
??? ??? ??? ? System.out.println("检查下解压的目录是否格式写错:例如给文件解压到E盘下的 demo文件夹下,路径应该写成:E:\\"+"\\demo\\"+"\\");
??? ??? ??? ? f++;
??? ??? }else{
??? ??? ??? while (ze != null) {
??? ??? ??? ??? String name = ze.getName();
??? ??? ??? ??? File child = new File(parent, name);
??? ??? ??? ??? FileOutputStream output = new FileOutputStream(child);
??? ??? ??? ??? byte[] buffer = new byte[10240];
??? ??? ??? ??? int bytesRead = 0;
??? ??? ??? ??? while ((bytesRead = zis.read(buffer)) > 0) {
??? ??? ??? ??? ??? output.write(buffer, 0, bytesRead);
??? ??? ??? ??? }
??? ??? ??? ??? output.flush();
??? ??? ??? ??? output.close();
??? ??? ??? ??? ze = zis.getNextEntry();
??? ??? ??? }
??? ??? }
??? ??? zis.close();
??? ?}
??? ?return f;
??? ??? ???
??? }

??? // 函数GetTestXlsFileName功能:遍历fileAbsolutePath目录下的所有指定扩展名文件
??? // 并将文件名保存在Vector中
??? @SuppressWarnings("unchecked")
??? public static List getTestXlsFileName(String fileAbsolutePath) {
??? ??? List list = new ArrayList();
??? ??? File file = new File(fileAbsolutePath);
??? ??? File[] subFile = file.listFiles();
??? ??? if(subFile!=null){
??? ??? for (int iFileLength = 0; iFileLength < subFile.length; iFileLength++) {
??? ??? ??? // 判断是否为文件夹
??? ??? ??? if (!subFile[iFileLength]