我正在尝试使用Apache Common的FileUtil来使用CopyDirectory将文件传输到其他磁盘上。但是,在传输我的文档时我遇到了一个错误。此外,我不知道为什么,但是当我选择像C:\ Users [UserName] \ Documents这样的特定路径时,它不会给我JUST文档中的内容,它给了我用户文件夹中的其他文件夹..我不知道这是为什么。当我在MyDocuments上运行CopyDirectory时,我也IOException ...当它试图复制MyMusic(我不知道它为什么这样做的第一个地方Java Apache Commons FileUTIL CopyDirectory异常
在我的代码中,它正确地复制收藏夹和桌面... 。虽然看似在收藏夹中的“收藏夹工具栏”已经改变了文件夹“链接”文件夹
任何帮助将是巨大的感谢
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.commons.io.*;
public class TransferJet {
public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
System.out.print("Please enter the username:");
String user = in.readLine();
System.out.print("Please enter the drive letter of the old primary partition:");
String oldPrimaryLetter = in.readLine();
System.out.print("Please enter the drive letter of the old secondary partition:");
String oldSecondaryLetter = in.readLine();
System.out.print("Please enter the drive letter of the new primary partition:");
String newPrimaryLetter = in.readLine();
System.out.print("Please enter the driver letter of the new secondary partition:");
String newSecondaryLetter = in.readLine();
if(user.equals("") || oldSecondaryLetter.equals("") || oldPrimaryLetter.equals("") || newPrimaryLetter.equals("") || newSecondaryLetter.equals(""))
{
System.out.println("Invalid directory or file name.");
System.exit(0);
}
String newFiles = "";
String oldFiles = "";
File source = null;
File destination = null;
System.out.println("Moving Favorites...");
oldFiles = oldPrimaryLetter + ":\\Users\\" + user + "\\Favorites";
//String oldFilesA = "C:\\Users\\ashih\\Favorites";
//String newFilesA = "G:\\Users\\ashih\\Favorites";
newFiles = newPrimaryLetter + ":\\Users\\" + user + "\\Favorites";
source = new File(oldFiles);
destination = new File(newFiles);
FileUtils.copyDirectory(source, destination);
System.out.println("Moving Desktop...");
oldFiles = oldPrimaryLetter + ":\\Users\\" + user + "\\Desktop";
newFiles = newPrimaryLetter + ":\\Users\\" + user + "\\Desktop";
source = new File(oldFiles);
destination = new File(newFiles);
FileUtils.copyDirectory(source, destination);
System.out.println("Moving My Documents...");
oldFiles = oldPrimaryLetter + ":\\Users\\" + user + "\\";
newFiles = newPrimaryLetter + ":\\Users\\" + user + "\\Documents";
source = new File(oldFiles);
destination = new File(newFiles);
FileUtils.copyDirectory(source, destination);
System.out.println("Moving Old Secondary to New Secondary...");
oldFiles = oldSecondaryLetter + ":\\";
newFiles = newSecondaryLetter + ":\\";
source = new File(oldFiles);
destination = new File(newFiles);
FileUtils.copyDirectory(source, destination);
}
}
有什么异常?主要的问题(我能想到的是我的头顶)是,你试图复制的许多目录实际上是“链接”(更准确地说,通常是连接点),Java/IO Commons可能不是能够处理 – MadProgrammer 2012-07-20 23:17:25
我不再在计算机上使用代码,但我相信它是MyMusic的IO Exception.IO(不记得具体的错误)。我尝试删除MyMusic文件夹以查看会发生什么,然后我收到了IOException(拒绝访问我的音乐)行。反正有链接到我的文档不是“链接”或有路口。我只是想要在我的文档文件夹中的内容... – Alan 2012-07-20 23:44:35