读取配置文件properties xml

1. 读取properies文件

        Properties prop = new Properties();
		InputStream in = B2bicSeverProperties.class.getClassLoader().getResourceAsStream("cn/com/trade365/config/sys/b2bic_sever.properties");
		
		try {
			prop.load(in);

			b2bic_ip = prop.getProperty("b2bic.sever.ip").trim();
			b2bic_port = Integer.parseInt(prop.getProperty("b2bic.sever.port").trim());
			buffersize = Integer.parseInt(prop.getProperty("b2bic.sever.buffersize").trim());
			nodelay = Boolean.parseBoolean(prop.getProperty("b2bic.sever.nodelay").trim());
			timeout = Integer.parseInt(prop.getProperty("b2bic.sever.timeout").trim());
			keepalive = Boolean.parseBoolean(prop.getProperty("b2bic.sever.keepalive").trim());
			
			uploadPath = prop.getProperty("b2bic.sever.upload.path").trim();
			downloadPath = prop.getProperty("b2bic.sever.download.path").trim();

			in.close();
		} catch (IOException e) {
			log.error(e);
		}

2. 读取xml文件

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();  
        try  
        {  
            DocumentBuilder db = dbf.newDocumentBuilder();  
            Document doc = db.parse("pet2.xml");  
  
            NodeList dogList = doc.getElementsByTagName("dog");  
            System.out.println("共有" + dogList.getLength() + "个dog节点");  
            for (int i = 0; i < dogList.getLength(); i++)  
            {  
                Node dog = dogList.item(i);  
                Element elem = (Element) dog;  
                System.out.println("id:" + elem.getAttribute("id"));  
                for (Node node = dog.getFirstChild(); node != null; node = node.getNextSibling())  
                {  
                    if (node.getNodeType() == Node.ELEMENT_NODE)  
                    {  
                        String name = node.getNodeName();  
                        String value = node.getFirstChild().getNodeValue();  
                        System.out.print(name + ":" + value + "\t");  
                    }  
                }  
                System.out.println();  
            }  
        }  
        
        

   
     
    
    
      
        
     
                 
            
      
      
       
       YAYA
      
        
            
      
      
       
       100
      
        
            
      
      
       
       0
      
        
            
      
      
       
       酷酷的雪娜瑞
      
        
        
     
       
        
     
                 
            
      
      
       
       OUOU
      
        
            
      
      
       
       90
      
        
            
      
      
       
       15
      
        
            
      
      
       
       聪明的拉布拉多犬
      
        
        
     
       
    
    
      
    
    
      
        
     
                 
            
      
      
       
       QQ
      
        
            
      
      
       
       100
      
        
            
      
      
       
       20
      
        
            
      
      
       
       Q仔
      
                   
        
     
               
    
    
      

   
    

        File lppzXmlFile = new ClassPathResource("com/lppz/delivery_corp.xml").getFile();
		Document document = new SAXReader().read(lppzXmlFile);
		List
   
   
    
     elements = document.selectNodes("//deliveryCorp");
		for (Element element : elements) {
			String key = element.attributeValue("name");
			String value = element.attributeValue("code");
			System.out.println("key:" + key +", value" + value);
		}
		

    
    
	
     
     
	
     
     

    
    
   
   

3. xml字符串和javabean相互转化

package cn.com.trade365.bank.pingan.zhilian.send;

import java.io.UnsupportedEncodingException;

import cn.com.trade365.bank.pingan.property.MessageContentProperties;
import cn.com.trade365.bank.pingan.property.MessageHeaderProperties;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("Result")
public class MC006 {
	
	private static final String TRANSACTION_CODE = "C006  "; 
	private static final String OP_FLAG = "2";
	private static final String PAGE_SIZE = "500";
	
	@XStreamAlias("MainAccount")
	private String mainAccount;
	
	@XStreamAlias("ReqSubAccount")
	private String reqSubAccount;
	
	@XStreamAlias("OpFlag")
	private String opFlag;
	
	@XStreamAlias("StartDate")
	private String startDate;
	
	@XStreamAlias("EndDate")
	private String endDate;
	
	@XStreamAlias("ReqLastSubAccNo")
	private String reqLastSubAccNo;
	
	@XStreamAlias("ReqLastDate")
	private String reqLastDate;
	
	@XStreamAlias("ReqLastJNo")
	private String reqLastJNo;
	
	@XStreamAlias("ReqLastSeq")
	private String reqLastSeq;
	
	@XStreamAlias("PageSize")
	private String pageSize;
	
	public MC006(){
		mainAccount = MessageContentProperties.agentaccno;
		opFlag = OP_FLAG;
		pageSize = PAGE_SIZE;
	}
	

	public String getMainAccount() {
		return mainAccount;
	}

	public void setMainAccount(String mainAccount) {
		this.mainAccount = mainAccount;
	}

	public String getReqSubAccount() {
		return reqSubAccount;
	}

	public void setReqSubAccount(String reqSubAccount) {
		this.reqSubAccount = reqSubAccount;
	}

	public String getOpFlag() {
		return opFlag;
	}

	public void setOpFlag(String opFlag) {
		this.opFlag = opFlag;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getReqLastSubAccNo() {
		return reqLastSubAccNo;
	}

	public void setReqLastSubAccNo(String reqLastSubAccNo) {
		this.reqLastSubAccNo = reqLastSubAccNo;
	}

	public String getReqLastDate() {
		return reqLastDate;
	}

	public void setReqLastDate(String reqLastDate) {
		this.reqLastDate = reqLastDate;
	}

	public String getReqLastJNo() {
		return reqLastJNo;
	}

	public void setReqLastJNo(String reqLastJNo) {
		this.reqLastJNo = reqLastJNo;
	}

	public String getReqLastSeq() {
		return reqLastSeq;
	}

	public void setReqLastSeq(String reqLastSeq) {
		this.reqLastSeq = reqLastSeq;
	}

	public String getPageSize() {
		return pageSize;
	}

	public void setPageSize(String pageSize) {
		this.pageSize = pageSize;
	}

	public static String getXmlMessage(MC006 input){
		XStream xStream = new XStream();
		
        xStream.setMode(XStream.NO_REFERENCES);
        xStream.processAnnotations(new Class[]{MC006.class});
        String xml = xStream.toXML(input);
		return xml;
	}
}



package cn.com.trade365.bank.pingan.zhilian.receive;

import java.util.List;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import com.thoughtworks.xstream.io.xml.DomDriver;

@XStreamAlias("Result")
public class MC006Res {
	
	@XStreamAlias("Count")
	private String count;
	
	@XStreamAlias("AllCount")
	private String allCount;
	
	@XStreamAlias("IsEnd")
	private String isEnd;
	
	@XStreamImplicit(itemFieldName="list")
	private List
   
   
    
     detailList;
	
	public String getCount() {
		return count;
	}

	public void setCount(String count) {
		this.count = count;
	}

	public String getAllCount() {
		return allCount;
	}

	public void setAllCount(String allCount) {
		this.allCount = allCount;
	}

	public String getIsEnd() {
		return isEnd;
	}

	public void setIsEnd(String isEnd) {
		this.isEnd = isEnd;
	}

	public List
    
    
     
      getDetailList() {
		return detailList;
	}

	public void setDetailList(List
     
     
      
       detailList) {
		this.detailList = detailList;
	}

	public static MC006Res xmlToC006Output(String xml){
		
		XStream xStream = new XStream(new DomDriver());
		xStream.processAnnotations(MC006Res.class);
		
		try{
			MC006Res res = (MC006Res) xStream.fromXML(xml);
			return res;
		}catch(Exception e){
			System.out.println(e);
		}
		return null;
	}
	
}


package cn.com.trade365.bank.pingan.zhilian.receive;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("list")
public class MC006Detail {
	
	@XStreamAlias("SubAccount")
	private String subAccount;
	
	@XStreamAlias("AccountDate")
	private String accountDate;
	
	@XStreamAlias("JournalNo")
	private String journalNo;
	
	@XStreamAlias("SeqNo")
	private String seqNo;
	
	@XStreamAlias("TranTime")
	private String tranTime;
	
	@XStreamAlias("MainAccount")
	private String mainAccount;
	
	@XStreamAlias("MainAccountName")
	private String mainAccountName;
	
	@XStreamAlias("SubAccoutName")
	private String subAccoutName;
	
	@XStreamAlias("DCFlag")
	private String dCFlag;
	
	@XStreamAlias("CcyCode")
	private String ccyCode;
	
	@XStreamAlias("TranAmount")
	private String tranAmount;
	
	@XStreamAlias("TxFlag")
	private String txFlag;
	
	@XStreamAlias("OppAccountNo")
	private String oppAccountNo;
	
	@XStreamAlias("OppAccountName")
	private String oppAccountName;
	
	@XStreamAlias("OppBankNo")
	private String oppBankNo;
	
	@XStreamAlias("OppBankName")
	private String oppBankName;
	
	@XStreamAlias("Remark")
	private String remark;

	public String getSubAccount() {
		return subAccount;
	}

	public void setSubAccount(String subAccount) {
		this.subAccount = subAccount;
	}

	public String getAccountDate() {
		return accountDate;
	}

	public void setAccountDate(String accountDate) {
		this.accountDate = accountDate;
	}

	public String getJournalNo() {
		return journalNo;
	}

	public void setJournalNo(String journalNo) {
		this.journalNo = journalNo;
	}

	public String getSeqNo() {
		return seqNo;
	}

	public void setSeqNo(String seqNo) {
		this.seqNo = seqNo;
	}

	public String getTranTime() {
		return tranTime;
	}

	public void setTranTime(String tranTime) {
		this.tranTime = tranTime;
	}

	public String getMainAccount() {
		return mainAccount;
	}

	public void setMainAccount(String mainAccount) {
		this.mainAccount = mainAccount;
	}

	public String getMainAccountName() {
		return mainAccountName;
	}

	public void setMainAccountName(String mainAccountName) {
		this.mainAccountName = mainAccountName;
	}

	public String getSubAccoutName() {
		return subAccoutName;
	}

	public void setSubAccoutName(String subAccoutName) {
		this.subAccoutName = subAccoutName;
	}

	public String getdCFlag() {
		return dCFlag;
	}

	public void setdCFlag(String dCFlag) {
		this.dCFlag = dCFlag;
	}

	public String getCcyCode() {
		return ccyCode;
	}

	public void setCcyCode(String ccyCode) {
		this.ccyCode = ccyCode;
	}

	public String getTranAmount() {
		return tranAmount;
	}

	public void setTranAmount(String tranAmount) {
		this.tranAmount = tranAmount;
	}

	public String getTxFlag() {
		return txFlag;
	}

	public void setTxFlag(String txFlag) {
		this.txFlag = txFlag;
	}

	public String getOppAccountNo() {
		return oppAccountNo;
	}

	public void setOppAccountNo(String oppAccountNo) {
		this.oppAccountNo = oppAccountNo;
	}

	public String getOppAccountName() {
		return oppAccountName;
	}

	public void setOppAccountName(String oppAccountName) {
		this.oppAccountName = oppAccountName;
	}

	public String getOppBankNo() {
		return oppBankNo;
	}

	public void setOppBankNo(String oppBankNo) {
		this.oppBankNo = oppBankNo;
	}

	public String getOppBankName() {
		return oppBankName;
	}

	public void setOppBankName(String oppBankName) {
		this.oppBankName = oppBankName;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
}


     
     
    
    
   
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值