我正在使用JDK 6
。
我有两个文件夹,它们的名称分别是Folder1
和Folder2
。
Folder1
中有以下文件:
TherMap.txt
TherMap1.txt
TherMap2.txt
每次
Folder2
只有一个名为TherMap.txt
的文件。我的需求是,从
folder1
中复制任何文件,并将其粘贴到以TherMap.txt
命名的Folder2
中。如果Folder2
中已经存在TherMap.txt
,则删除并粘贴它。我编写了以下代码,但它不起作用:
public void FileMoving(String sourceFilePath, String destinationPath, String fileName) throws IOException {
File destinationPathObject = new File(destinationPath);
File sourceFilePathObject = new File(sourceFilePath);
if ((destinationPathObject.isDirectory()) && (sourceFilePathObject.isFile()))
//both source and destination paths are available
{
//creating object for File class
File statusFileNameObject = new File(destinationPath + "/" + fileName);
if (statusFileNameObject.isFile())
//Already file is exists in Destination path
{
//deleted File
statusFileNameObject.delete();
//paste file from source to Destination path with fileName as value of fileName argument
FileUtils.copyFile(sourceFilePathObject, statusFileNameObject);
}
//File is not exists in Destination path.
{
//paste file from source to Destination path with fileName as value of fileName argument
FileUtils.copyFile(sourceFilePathObject, statusFileNameObject);
}
}
}
我在main()
函数中调用上述函数。
//ExternalFileExecutionsObject is class object
ExternalFileExecutionsObject.FileMoving(
"C:/Documents and Settings/mahesh/Desktop/InputFiles/TMapInput1.txt",
"C:/Documents and Settings/mahesh/Desktop/Rods",
"TMapInput.txt");
当我使用
FileUtils
函数时,它出现了错误,因此我单击错误,自动产生了以下代码的新包。 package org.apache.commons.io;
import java.io.File;
public class FileUtils {
public static void copyFile(File sourceFilePathObject,
File statusFileNameObject) {
// TODO Auto-generated method stub
}
}
我的代码没有显示任何错误,但是它不起作用。
我该如何修复它?
谢谢。