我正在使用JDK 6
.
我有 2 个文件夹名称是Folder1
和Folder2
。
Folder1
有以下文件
TherMap.txt
TherMap1.txt
TherMap2.txt
每次Folder2
只有一个文件名为TherMap.txt
.
我想要的是,
复制任何文件folder1
并将其粘贴到Folder2
名称为TherMap.txt
. 如果已TherMap.txt
存在于 中Folder2
,则删除并粘贴它。
因为我写了以下代码。但它不起作用
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
}
}
我的代码没有显示任何错误,即使它不起作用。
我怎样才能解决这个问题。
谢谢