public class XXUpdate
{
/**
* 命令行入口
* 输入参数:新版本XX路径、旧版本XX路径、更新文件路径
*
* @param args
*/
public static void main(String args[])
{
String newXXPath = args[0];
String oldXXPath = args[1];
String updatePath = args[2];
File newXX = new File(newXXPath);
if (!newXX.exists())
{
System.out.println("输入的文件路径有误!");
return;
}
if (!copyNewFiles(newXX, newXXPath, oldXXPath, updatePath))
{
System.out.println("拷贝失败!");
}
}
/**
* 拷贝所有更新的文件
*
* @param newXX
* @param newXXPath
* @param oldXXPath
* @param updatePath
* @return
*/
private static boolean copyNewFiles(File newXX, String newXXPath,
String oldXXPath, String updatePath)
{
boolean isSucceed = true;
if (newXX.isDirectory())
{
File[] subFiles = newXX.listFiles();
int len = subFiles.length;
File newXXFile;
File oldXXFile;
for (int i = 0; (i < len) && isSucceed; i++)
{
newXXFile = subFiles[i];
String relativePathStr = FileUtils.getRelativePath(newXXPath,
newXXFile.getAbsolutePath());
oldXXFile = new File(oldXXPath + "/" + relativePathStr);
if (newXXFile.isDirectory())
{
isSucceed = copyNewFiles(newXXFile,
newXXPath,
oldXXPath,
updatePath);
}
else
{
if (!oldXXFile.exists()
|| !MD5Utils.getMD5(newXXFile)
.equals(MD5Utils.getMD5(oldXXFile)))
{
isSucceed = FileUtils.copyFile(newXXFile.getAbsolutePath(),
updatePath + "/" + relativePathStr);
}
}
}
}
return isSucceed;
}
}