日期:2014-05-20 浏览次数:20848 次
#!C:\Python27 python # -*- coding:UTF-8 -*- import os,sys size = 80*1024*1024 partnum = 0 input = open("c:\\test.zip",'rb') text = input.read(size) while text: partnum = partnum + 1 fileoutput = open("c:\\ttt\\test%04d"%partnum+".zip",'wb') fileoutput.write(text) fileoutput.close() text = input.read(size) input.close()
------解决方案--------------------
package com.huawei.hdm.util; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; /** * The StrutsXMLParser class parse struts.xml. */ public class StrutsXMLParser { Map<String, Object> map = new HashMap<String, Object>(); class StrutsXMLHandler extends SAXHandler { private String cls; private boolean isUrl; private List<String> fileList = new ArrayList<String>(); @Override public void startDocument() throws SAXException { } @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if("include".equals(qName)) { fileList.add(atts.getValue("file")); } if("constant".equals(qName)) { map.put(atts.getValue("name"), atts.getValue("value")); } if("action".equals(qName)) { cls = atts.getValue("class"); } if("result".equals(qName) && "error".equals(atts.getValue("name"))) { isUrl = true; } } @Override public void characters(char[] ch, int start, int length) throws SAXException { if(cls != null && isUrl) { String url = new String(ch, start, length); if(!map.containsKey(cls)) { cls = cls.substring(cls.lastIndexOf(".") + 1); map.put(cls, url); } isUrl = false; cls = null; } } @Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { } @SuppressWarnings("unchecked") @Override public void endDocument() throws SAXException { if(fileList.size() > 0) { map.put("fileList", fileList); } } } @SuppressWarnings("unchecked") public Map<String, Object> parser(String xml) throws Exception { String path = xml.substring(0, xml.lastIndexOf("/") + 1); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); StrutsXMLHandler handler = new StrutsXMLHandler(); xr.setContentHandler(handler); xr.parse(xml); List<String> fileList = (List<String>) map.get("fileList"); if(fileList != null) { map.remove("fileList"); Iterator it = fileList.iterator(); while(it.hasNext()) { parser(path + it.next()); } } return map; } public static void main(String[] args) { try { Map<String, Object> map = new StrutsXMLParser().parser("struts.xml"); Iterator<String> it = map.keySet().iterator(); while(it.hasNext()) { String key = it.next(); String val = String.valueOf(map.get(key)); System.err.println(key + " = " + val); } } catch(Exception e) { e.printStackTrace(); } } }