一个简单的解压ZIP Excl文件--->按时间读取Excle文件,通过Fat jar打成jar相对应的添加到mysql数据库中。
??? ??? ??? ? 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].isDirectory()) {
??? ??? ??? ??? String tempName = subFile[iFileLength].getName();
??? ??? ??? ??? // 判断是否为xls或xlsx结尾
??? ??? ??? ??? if (tempName.trim().toLowerCase().endsWith(".xls")
??? ??? ??? ??? ??? ??? || tempName.trim().toLowerCase().endsWith(".xlsx")) {
??? ??? ??? ??? ??? // 去掉tXXXX.xls文件的首字母t
??? ??? ??? ??? ??? // String fileName = tempName.substring(1);
??? ??? ??? ??? ??? list.add(tempName);
??? ??? ??? ??? }
??? ??? ??? }
??? ??? }
??? ???
??? ??? }
??? ??? return list;
??? }
??? public static int OperatingExcl(String objectPath,String directory)
??? ??? ??? throws Exception {
??? ??? ?int flag=0;
??? ??? String pathoperratingExcl = directory + objectPath;
??? ??? // 定义一个文件类
??? ??? InputStream is = null;
??? ??? // 定义一个工作book
??? ??? Workbook workBook = null;
??? ??? is = new FileInputStream(pathoperratingExcl);
??? ??? // 获取值
??? ??? workBook = Workbook.getWorkbook(is);
??? ??? // 获取哪一页sheet
??? ??? Sheet sheet = workBook.getSheet(0);
??? ??? @SuppressWarnings("unused")
??? ??? Cell cell = null;
??? ??? String driver = "com.mysql.jdbc.Driver";
??? ??? String url = "jdbc:mysql://xx.xx.xx.xx:3306/realpay?useUnicode=true&characterEncoding=UTF-8";
??? ??? String user = "xx";
??? ??? String password = "xx";
??? ??? Class.forName(driver);
??? ??? Connection conn = DriverManager.getConnection(url, user, password);
??? ??? Statement statement = conn.createStatement();
??? ??? for (int j = 1; j < sheet.getRows(); j++) {
??? ??? ?? if(!sheet.getCell(1, j).getContents().equals("")){
??? ??? ??? String order_no=null;
??? ??? ??? String sp_order_no=null;
??? ??? ??? String order_status=null;
??? ??? ??? String shengfen=null;
??? ??? ??? String yunyingshang=null;
??? ??? ??? String amount=null;
??? ??? ??? String order_date=null;
??? ??? ??? String liushui=null;
??? ??? ??? String phone=null;
??? ??? ??? String danjia=null;
??? ??? ??? String shifu=null;
??? ??? ??? String daozhang=null;
??? ??? ??? String tuikuan=null;
??? ??? ??? String create_date=null;
??? ??? ??? String update_date=null;
??? ??? ??? String this_status=null;
??? ??? ??? ??? order_no=sheet.getCell(2, j).getContents();
??? ??? ??? ??? sp_order_no=sheet.getCell(3, j).getContents();
??? ??? ??? ??? String order_status1=sheet.getCell(15, j).getContents();
??? ??? ??? ??? if(order_status1.equals("失败")){
??? ??? ??? ??? ??? order_status="0";
??? ??? ??? ??? }else if(order_status1.equals("成功")){
??? ??? ??? ??? ??? order_status="1";
??? ??? ??? ??? }else if(order_status1.equals(" ")){
??? ??? ??? ??? ??? order_status="2";
??? ??? ??? ??? }else if(order_status1.equals("未付款")){
??? ??? ??? ??? ??? order_status="3";
??? ??? ??? ??? }else if(order_status1.equals("部分退款")){
??? ??? ??? ??? ??? order_status="4";
??? ??? ??? ??? }else{
??? ??? ??? ??? ??? order_status="2";
??? ??? ??? ??? }
??? ??? ??? ??? shengfen=sheet.getCell(6, j).getContents();
??? ??? ??? ??? yunyingshang=sheet.getCell(7, j).getContents();
??? ??? ??? ??? amount=sheet.getCell(9, j).getContents();
??? ??? ??? ??? String ddd=sheet.getCell(1, j).getContents();
??? ??? ??? ??? int index = ddd.indexOf(".");
??? ??? ??? ??? String dddd=ddd.substring(0,index);
??? ??? ??? ??? order_date=dddd;
??? ??? ??? ??? liushui=sheet.getCell(4, j).getContents();
??? ??? ??? ??? phone=sheet.getCell(10, j).getContents();
??? ??? ??? ??? danjia=sheet.getCell(11, j).getContents();
??? ??? ??? ??? shifu=sheet.getCell(12, j).getContents();
??? ??? ??? ??? daozhang=sheet.getCell(13, j).getContents();
??? ??? ??? ??? tuikuan=sheet.getCell(14, j).getContents();
??? ??? ??? ??? SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
??? ??? ??? ??? create_date=sdf.format(new Date());
??? ??? ??? ??? update_date="0000-00-00 00:00:00";
??? ??? ??? ??? this_status="1";
??? ??? ??? ??? String sql = "INSERT INTO gaoyang_checking(order_no,sp_order_no,order_status,shengfen,yunyingshang,amount,order_date,liushui,phone,danjia,shifu,daozhang,tuikuan,create_date,update_date,this_status)" +
??? ??? ??? ??? "VALUES" +
??? ??? ??? ??? "('"+order_no+"','"+sp_order_no+"','"+order_status+"','"+shengfen+"','"+yunyingshang+"'," +
??? ??? ??? ??? ?"'"+amount+"','"+order_date+"','"+liushui+"','"+phone+"','"+danjia+"'" +
??? ??? ??? ??? ?",'"+shifu+"','"+daozhang+"','"+tuikuan+"','"+create_date+"','"+update_date+"','"+this_status+"')";
??? ??? ??? ??? int? rs = statement.executeUpdate(sql);
??? ??? ??? ??? if(rs>0){
??? ??? ??? ??? ??? //System.out.println("添加成功》》》》"+j);
??? ??? ??? ??? ??? flag++;
??? ??? ??? ??? }else{
??? ??? ??? ??? ??? System.out.println("添加失败》》》》");
??? ??? ??? ??? ??? System.out.println("失败的sql"+sql);
??? ??? ??? ??? }
??? ??? ?? }
??? ??? }
??? ??? conn.close();?
??? ??? conn.close();
??? ??? workBook.close();
??? ??? return flag;
??? }
??? public static int DelOperatingExcl(String objectPath){
??? ??? int id=0;
??? ??? try {
??? ??? ??? String driver = "com.mysql.jdbc.Driver";
??? ??? ??? String url = "jdbc:mysql://1xx.1xx8.1.2xx2:3306/realpay?useUnicode=true&characterEncoding=UTF-8";
??? ??? ??? String user = "xx";
??? ??? ??? String password = "xx";
??? ??? ??? Class.forName(driver);
??? ??? ??? Connection conn = DriverManager.getConnection(url, user, password);
??? ??? ??? Statement statement = conn.createStatement();
??? ??? ??? String sql = "DELETE? FROM gaoyang_checking? WHERE order_date LIKE '%"+objectPath+"%'";
??? ??? ??? System.out.println(sql);
??? ??? ??? id = statement.executeUpdate(sql);
??? ??? ???
??? ??? ??? conn.close();?
??? ??? ??? conn.close();
??? ??? } catch (Exception e) {
??? ??? ??? e.printStackTrace();
??? ??? }
??? ??? return id;
??? }
??? /**
??? ?* 读取excl文件并给存入到Map中去
??? ?*
??? ?* @throws Exception
??? ?*/
??? @SuppressWarnings("unchecked")
??? public static void readExcl(String adatete,String directory,String stringg) throws Exception {
??? ??? int j=0;
??? ??? //解压到的文件?? 解压文件
??? ??? int zipa=unzipFile(directory,stringg);
??? ?if(zipa<1){
??? ??? //String y=adatete.split("-")[1].split("-")[0];
//??? ??? String m=adatete.split("-")[0];
//??? ??? String d=adatete.split("-")[2];
??? ??? String f1=adatete.substring(0,4);
??? ??? String f2=adatete.substring(4,6);
??? ??? String f3=adatete.substring(6,8);
??? ??? String zTime=f1+"-"+f2+"-"+f3;
??? ??? List list = getTestXlsFileName(directory);
??? ??? String pas="DL20111213003195_"+adatete+".xls";
??? ??? for (int i = 0; i < list.size(); i++) {
??? ??? ??? //System.out.println(list.get(i));
??? ??? ??? if(pas.equals(list.get(i))){
??? ??? ??? ??? int shan=DelOperatingExcl(zTime);
??? ??? ??? ??? ??? if(shan>0){
??? ??? ??? ??? ??? ??? System.out.println("数据库有"+adatete+"记录,已经删除!");
??? ??? ??? ??? ??? }else{
??? ??? ??? ??? ??? ??? System.out.println("数据库未有"+adatete+"记录!");
??? ??? ??? ??? }
??? ??? ??? ???
??? ??? ??? ??? //路径?? 要添加的路径
??? ??? ??? ??? int chenggong=OperatingExcl(pas,directory);
??? ??? ??? ??? System.out.println("添加已经结束,添加了:"+chenggong+"条!");
??? ??? ??? }else{
??? ??? ??? ??? j++;
??? ??? ??? }
??? ??? ??? if(j==list.size()){
??? ??? ??? ??? System.out.println("没有找到"+adatete+"日期相对应的excel文件文件");
??? ??? ??? ??? System.out.println("1、当天没有文件,2、检查下日期是否写错,例如2012年2月9号的必须写成:20120209");
??? ??? ??? }
??? ??? }
??? ??? ?
??? ?}
??? }
??? public static void main(String[] args) {
??? ??? try {
??? ??? ??? int dd=args.length;
??? ??? ??? if(dd==3){
??? ??? ??? ??? System.out.println(dd);
??? ??? ??? ??? String adatete = args[0];
??? ??? ??? ??? String directory = args[1];
??? ??? ??? ??? String stringg = args[2];
??? ??? ??? ??? if(adatete.equals("") || adatete==null){
??? ??? ??? ??? ??? System.out.println("请按顺序输入3个参数,1 日期、2解压到的目录 、3需要解压的文件目录");
??? ??? ??? ??? }else if(directory.equals("") || directory==null){
??? ??? ??? ??? ??? System.out.println("请按顺序输入3个参数,1 日期、2解压到的目录 、3需要解压的文件目录");
??? ??? ??? ??? }else if(directory.equals("")? || directory==null){
??? ??? ??? ??? ??? System.out.println("请按顺序输入3个参数,1 日期、2解压到的目录 、3需要解压的文件目录");
??? ??? ??? ??? }else{
??? ??? ??? ??? ??? readExcl(adatete,directory,stringg);
??? ??? ??? ??? }
??? ??? ??? }else{
??? ??? ??? ??? System.out.println("请按顺序输入3个参数,1 日期、2解压到的目录 、3需要解压的文件目录");
??? ??? ??? }
??? ??? ???
//??? ??? ??? String m=adatete.split("-")[0];
//??? ??? ??? String d=adatete.split("-")[2];
??? ???
??? ??? //readExcl("20120229","E:\\demo\","F:\\缴费网\\DL20111213003195.zip");
??? ??? } catch (Exception e) {
??? ??? ??? e.printStackTrace();
??? ??? }
??? }
}
?
在eclipse下安装fat jar插件进行给项目打成jar包:
安装:
?
?
问题:有两个项目,他们都是两个引用包(没main入口)。像这样

??这两个项目,kernel是最底层的引用包,而androidConnection也是一个引用了kernel包的引用包,现在我想打包androidConnection,但是用普通的import成jar是不包括kernel的jar的。
因此搜索了一下,网上大概有几个不错的方法,这里我打算用fatjar,因为它作为eclipse的插件,用起来够傻瓜式的,很方便。^-^
//////////////////////////下面是截取网上的教材////////////////////
???????查看Eclipse如何打包的过程中我发现有个fatjar插件功能更强些,可以把需要的资源打进一个jar里。所以下载了一个,下载地址:http://sourceforge.net/project/showfiles.php?group_id=115990&package_id=125924?解压缩后是一个.../plugins/(net...)把plugins下面的(net..)文件夹拷贝到eclipse的plugins下,重新启动Eclipse3.1,Windows=>prefernce=>fat jar preference看到他就说明已经安装成功了。如果没有看到,没有关系,删除D:\eclipse310\configuration\org.eclipse.update\platform.xml文件(此文件可以自动生成)不用担心以前的插件会因此而消失,没事。
????? ??刚开始找不到如何使用它,后来看到你的项目=〉Export..=>向导里有fat jar =>使用起来真的很方便。

?
(上面图片的红色框主要是填你的入口函数,当然引用包是没有的,因此你可以直接跳过什么都不用填,生成出来的jar包它会自动将你所引用到的其他jar包也包括进来)
总结:
一般把src打包export=>Jar File?即可。
想把src附属的资源一起打包,必须使用FatJar => export..=>FatJar.
?
?
?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
最后在运行Jar包:cmd:? java -jar?? F:\Myeclipsworkspace\javaExcleDemo\javaExcleDemo_fat.jar??? E:\\demo\\??? F:\\缴费网\\DL20111213003195.zip?
?
?
?
?
最后运行结果:
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?