直接读取文件内容,不需要生成临时文件 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);
使用SVNRepository 获取文件历史版本内容
最新推荐文章于 2024-04-10 15:28:21 发布