如何在java中以svn的形式将路径作为字符串进行检查

时间:2015-04-14 05:48:09

标签: java svn

我有一个java代码,用于检查命令行中提到的svn路径。但是我希望将svn路径作为字符串传递,因为该路径会根据请求不断更改。 我的java代码是:

public class DisplayFile {
List<String> fileList;
public static void main(String[] args) throws IOException, InterruptedException {
    String a = "http://interactive/svn/Test/";
     String command = "svn co --username username --password password $a /home/aaa/ ";
     Process proc = Runtime.getRuntime().exec(command);
     // Read the output
     BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
     String line = "";
     while((line = reader.readLine()) != null) {
         System.out.print(line + "\n");
     }
     proc.waitFor();  
}

} 这时当我发出命令

String command = "svn co --username username --password password http://interactive/svn/Test/ /home/aaa/ ";

然后它有效。但我不想直接给svnpath。有什么方法可以解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

作为SVNKit开发人员,我建议您更喜欢基于SvnOperationFactory的新API。旧的API(基于SVNClientManager)仍然可以运行,但所有新的SVN功能都只能用于新的API。

final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {

    final SvnCheckout checkout = svnOperationFactory.createCheckout();
    checkout.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
    checkout.setSource(SvnTarget.fromURL(url));
    //... other options
    checkout.run();
}finally {

    svnOperationFactory.dispose();
}

答案 1 :(得分:0)

$java DisplayFile http://interactive/svn/Test/

public static void main(String[] args) throws IOException, InterruptedException {

String path = args[0];
String command = "svn co --username username --password password " + path + " /home/aaa/ ";

那样的东西?