zoukankan      html  css  js  c++  java
  • 打包工具开发随记

    zip.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="compress" default="zip">
      <property name="mulu" value="e:/XTH_caozuo/ant+jdom/new" />
      <property name="mubiaowenjian" value="e:/XTH_caozuo/ant+jdom/new/sunzekun" />
      <target name="zip">
        <zip destfile="${mubiaowenjian}.zip" >
        <fileset dir="${mulu}">
        	<include name="**/*.txt"/>
        </fileset>
        </zip>
      </target>
    </project>
    

    unzip.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="compress" default="zip">
      <property name="jieyamulu" value="e://XTH_caozuo/ant+jdom/new" />
      <property name="jieyawenjian" value="d://xutianhao_caozuo/sunzekun.zip" />
      <target name="zip">
        <unzip src="${jieyawenjian}" dest="${jieyamulu}" />
      </target>
    </project>
    

    zip.java

    package sample;
    
    import java.io.IOException;
    import java.util.List;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    
    public class Sample2 {
    
    	/**
    	 * @param args
    	 * @throws IOException 
    	 * @throws JDOMException 
    	 */
    	//文件zip打包 
    	
    	public static void main(String[] args) throws JDOMException, IOException {
    		// TODO Auto-generated method stub
    		SAXBuilder sb=new SAXBuilder();
    		Document doc=sb.build("zip.xml");
    		Element root =doc.getRootElement();
    		List<Element> lst=root.getChildren("property");
    		for(Element el :lst)
    		{
    			if(el.getAttributeValue("name").equals("mubiaowenjian"))
    				el.setAttribute("value", "d://sunzekun");
    		}//找寻属性名name为目标文件的子元素   修改value属性 
    		SaveXml.saveXML(doc);
    		Runtime.getRuntime().exec("cmd /k ant -f zip.xml");
    		//通过在cmd执行ant命令执行build.xml
    		System.out.println("chenggong");
    	}
    	
    }
    

    unzip.java

    package sample;
    
    import java.io.IOException;
    import java.util.List;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.JDOMException;
    import org.jdom.input.SAXBuilder;
    
    public class Unzip {
    
    	/**
    	 * @param args
    	 * @throws IOException 
    	 * @throws JDOMException 
    	 */
    	//文件zip打包 
    	
    	public static void main(String[] args) throws JDOMException, IOException {
    		// TODO Auto-generated method stub
    		SAXBuilder sb=new SAXBuilder();
    		Document doc=sb.build("unzip.xml");
    		Element root =doc.getRootElement();
    		List<Element> lst=root.getChildren("property");
    		for(Element el :lst)
    		{
    			if(el.getAttributeValue("name").equals("jieyawenjian"))
    				el.setAttribute("value", "d://xutianhao_caozuo/sunzekun.zip");
    			if(el.getAttributeValue("name").equals("jieyamulu"))
    				el.setAttribute("value","e://XTH_caozuo/ant+jdom/new");
    		}//找寻属性名name为目标文件的子元素   修改value属性 
    		SaveXml.saveXML(doc);
    		Runtime.getRuntime().exec("cmd /k ant -f unzip.xml");
    		//通过在cmd执行ant命令执行build.xml
    		System.out.println("chenggong");
    	}
    	
    }
    
  • 相关阅读:
    洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth 题解
    洛谷 P1957 口算练习题 题解
    洛谷 P2036 Perket 题解
    洛谷 P2369 EXCEEDED WARNING A 题解
    洛谷 P1184高手之在一起 题解
    洛谷 P1897电梯里的爱情 题解
    Python做的眼睛护士
    Python-Tkinter的Entry详解
    Python的TkinterButton做为父窗口
    Python用Tkinter的Frame实现眼睛护士的倒计时黑色屏幕
  • 原文地址:https://www.cnblogs.com/tianhao/p/4239766.html
Copyright © 2011-2022 走看看