使用SVNRepository 获取文件历史版本内容

直接读取文件内容,不需要生成临时文件
String username="*******";
String password="########";
String url="";//svn地址
String filepath ="/test/test.java";//文件路径
long version=112;//文件版本
String charset ="UTF-8";

//初始化版本库
DAVRepositoryFactory.setup();//加载https协议、
SVNRepositoryFactoryImpl.setup();//加载svn协议
FSRepositoryFactory.setup(); //
SVNRepository respository=null;
try{
    respository= DAVRepositoryFactory.create(SVNURL.parseURIEncoded(url));
    ISVNAuthenticationManager authenticationManager=SVNWCUtil.createDefaultAuthenticationManager(username,password.toCharArray());
    respository.setAuthenticationManager(authenticationManager);
}catch(Exception e){
    e.printStackTrace();
}

String  content="";
ByteArrayOutputStream baos=null;
try{

    SVNNodeKind nodeKind = respository.checkPath( filepath , -1 );
    if  (nodeKind == SVNNodeKind.NONE ||nodeKind == SVNNodeKind.DIR ) {
    }else{
        SVNProperties properties  =  new  SVNProperties();
        baos = new ByteArrayOutputStream( );
        respository.getFile(filepath , version, properties , baos );
        try{
            content=  baos.toString(charset);
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}catch(SVNException e){
    e.printStackTrace();
}finally {
    try{
        if(baos!=null){
            baos.close();
        }
    }catch(Exception e){
    }
}
System.out.println("文本内容"+content);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值