我越來越創建文件夾從文本
newDir D:\template_export\template\attachments\processed\enumeration\blocker.gif\enumeration\critical.gif\enumeration\high.gif\enumeration\low.gif\enumeration\major.gif\enumeration\medium.gif\enumeration\minor.gif\enumeration\normal.gif\enumeration\unassigned.gif\enumeration\unassigned2.gif\workflow\close.gif\workflow\defer.gif\workflow\duplicate.gif\workflow\inprogress.gif\workflow\new.gif\workflow\open.gif\workflow\reject.gif\workflow\remind.gif\workflow\reopen.gif\workflow\resolve.gif\workflow\unconfigure.gif\workflow\unresolve.gif\workflow\verify.gif\workflow\wontdo.gif\workflow\works.gif\workitemtype\bug.gif\workitemtype\enhancement.gif\workitemtype\general.gif\workitemtype\task.gif\workitemtype
new directory false
reached
java.nio.file.NoSuchFileException: D:\template_export\template\attachments\1.gif -> D:\template_export\template\attachments\processed\enumeration\blocker.gif\enumeration\critical.gif\enumeration\high.gif\enumeration\low.gif\enumeration\major.gif\enumeration\medium.gif\enumeration\minor.gif\enumeration\normal.gif\enumeration\unassigned.gif\enumeration\unassigned2.gif\workflow\close.gif\workflow\defer.gif\workflow\duplicate.gif\workflow\inprogress.gif\workflow\new.gif\workflow\open.gif\workflow\reject.gif\workflow\remind.gif\workflow\reopen.gif\workflow\resolve.gif\workflow\unconfigure.gif\workflow\unresolve.gif\workflow\verify.gif\workflow\wontdo.gif\workflow\works.gif\workitemtype\bug.gif\workitemtype\enhancement.gif\workitemtype\general.gif\workitemtype\task.gif\workitemtype\unknown.gifprocess_template_license.htmltemplate.messagestemplate_en_US.messages
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileCopy.move(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.move(Unknown Source)
at java.nio.file.Files.move(Unknown Source)
at Test.main(Test.java:60)
Error.
我的代碼是:
public class Test {
public static void main(String[] args) {
File orgDirectory = new File("D://template_export/template/attachments"); // replace this filename
// with the path to the folder
// that contains the original images
String fileContent = "";
try (BufferedReader br = new BufferedReader(new FileReader(new File(orgDirectory, "attachments.txt")))) {
for (String line;
(line = br.readLine()) != null;) {
fileContent += line;
}
} catch (Exception e) {
e.printStackTrace();
}
String[] newLocations = fileContent.split(",");
File[] orgFiles = orgDirectory.listFiles(new FileFilter() {@Override
public boolean accept(File pathname) {
return pathname.getPath().endsWith(".gif");
}
});
File destinationFolder = new File("D://template_export/template/attachments/processed");
if (!destinationFolder.exists()) {
System.out.println("here" + destinationFolder.mkdir());
}
int max = Math.min(orgFiles.length, newLocations.length);
for (int i = 0; i < max; i++) {
String newLocation = newLocations[i];
int lastIndex = newLocation.lastIndexOf("/");
if (lastIndex == -1) {
continue;
}
String newDirName = newLocation.substring(0, lastIndex);
System.out.println("newDirName " + newDirName);
String newName = newLocation.substring(lastIndex);
System.out.println("newName " + newName);
File newDir = new File(destinationFolder, newDirName);
System.out.println("newDir " + newDir);
if (!newDir.exists()) {
System.out.println("new directory " + newDir.mkdir());
}
try {
System.out.println("reached");
Files.move(orgFiles[i].toPath(), new File(newDir, newName).toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
}
}
您從文件Concat的臺詞沒有','然後用','將它分割成newLocations(可能你在這一點上只獲得一個項目?) – griFlo