FileUtils copyFile方法 詳解~~
阿新 • • 發佈:2019-01-07
public static void main(String[] args)
{
// 源File物件
File source = new File("ajava.txt");
// 備份的File物件
File target = new File("ajava-backup.txt");
//通過JVM讀取java.io.tmpdir屬性取得臨時資料夾
File targetDir = new File(System.getProperty("java.io.tmpdir"));
try
{
//在同一個資料夾複製檔案
System.out.println("複製 " + source + " 檔案到 " + target);
FileUtils.copyFile(source, target);
// 根據指定的資料夾複製
System.out.println("複製 " + source + " 檔案到" + targetDir + "目錄");
FileUtils.copyFileToDirectory(source, targetDir);
} catch (IOException e)
{
// Errors will be reported here if any error occures during copying
// the file
e.printStackTrace();
}
}
{
// 源File物件
File source = new File("ajava.txt");
// 備份的File物件
File target = new File("ajava-backup.txt");
//通過JVM讀取java.io.tmpdir屬性取得臨時資料夾
File targetDir = new File(System.getProperty("java.io.tmpdir"));
try
{
//在同一個資料夾複製檔案
System.out.println("複製 " + source + " 檔案到 " + target);
FileUtils.copyFile(source, target);
// 根據指定的資料夾複製
System.out.println("複製 " + source + " 檔案到" + targetDir + "目錄");
FileUtils.copyFileToDirectory(source, targetDir);
} catch (IOException e)
{
// Errors will be reported here if any error occures during copying
// the file
e.printStackTrace();
}
}