我想使用 Runtime.exec() 从 Java 调用 rsync 并且我想忽略隐藏的文件/文件夹。该命令很简单,并且在命令行中就像一个魅力。
rsync -r --exclude=".*" source destination
我尝试了很多很多不同的组合来正确分解这些参数,以便作为 String[] 传递给 exec()。我失败了,我可能快要失去理智了。
我尝试过的一些例子
String[]{ "rsync", "-r", "--exclude", "=", ".*", source, destination});
String[]{ "rsync", "-r", "--exclude", "=", "\".*\"", source, destination});
String[]{ "rsync", "-r", "--exclude=\".*\"", source, destination});
大多数情况下,我以退出 23(即“由于错误导致的部分传输”)结束,传输完成,但包含隐藏文件/文件夹。