Code generator will be used xml

package com.gzcgxt.erp.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.junit.Test;

public class MapperXML {
    
    @Test
    public void test1() throws Exception {
        
        String header= newxml();
        
        String footer= old();
        
        StringBuffer sb=new StringBuffer();
        
        sb.append(header).append(footer);
        
        File f=new File("d:/UserMapper.xml");
        
        FileOutputStream out=new FileOutputStream(f);
        
        out.write(sb.toString().getBytes());
        
        out.close();
        
    }
    
    
    public String old() throws Exception
    {
        File f=new File("c:/UserMapper.xml");
        
        FileInputStream in=new FileInputStream(f);
        
        byte[] buffer=new byte[1024];
        
        int len=-1;
        
        StringBuffer sb=new StringBuffer();
        while((len=in.read(buffer))!=-1)
        {
            String s=new String(buffer,0,len);
            sb.append(s);
        }
        
        in.close();
        
        String[] arr = sb.toString().split("</resultMap>");
        
        return arr[1];
        
    }
    
    
    public String newxml() throws Exception
    {
        File f=new File("e:/UserMapper.xml");
        
        FileInputStream in=new FileInputStream(f);
        
        byte[] buffer=new byte[1024];
        
        int len=-1;
        
        StringBuffer sb=new StringBuffer();
        while((len=in.read(buffer))!=-1)
        {
            String s=new String(buffer,0,len);
            sb.append(s);
        }
        
        in.close();
        
        String[] arr = sb.toString().split("</resultMap>");
        
        String s= arr[0];
        
        s=s+"</resultMap>";
        
        return s;
        
    }
    
    
    
}

 

Guess you like

Origin www.cnblogs.com/hua900822/p/11706372.html