java 中更改文件路径可以用file.renameTo 方法
public static void moveDataFile2Reject() throws Exception {
try {
//String dataFilePath = PropertyUtil.getString(PropertyUtil.INPUT_FILE_PATH_KEY);
//String rejectFilePath = PropertyUtil.getString(PropertyUtil.REJECT_FILE__PATH_KEY);
String dataFilePath = "D:\\a\b";
String rejectFilePath = "D:\\a\reject";
File file = new File(dataFilePath);
File[] files = file.listFiles();
for (File f : files) {
if(f.isFile())
{
f.renameTo(new File(rejectFilePath + f.getName()));
}
}
} catch (Exception e) {
logger.error("moveInFile2Reject Failed" , e);
}
}
//java api:
Renames the file denoted by this abstract pathname.
Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.