0
我想從我的.jar文件存在的位置複製目錄? 這裏是我嘗試..但我總是得到/家/用戶/ 我怎麼能從我的.jar程序存在的地方複製文件?在java中使用.jar程序複製目錄
private void copy_dir() {
//Path sourceParentFolder = Paths.get(System.getProperty("user.dir") + "/Project/");
// Path sourceParentFolder = Paths.get(Paths.get(".").toAbsolutePath().normalize().toString());
Path destinationParentFolder = Paths.get(System.getProperty("user.home"));
try {
Stream<Path> allFilesPathStream = Files.walk(sourceParentFolder);
Consumer<? super Path> action = new Consumer<Path>() {
@Override
public void accept(Path t) {
try {
String destinationPath = t.toString().replaceAll(sourceParentFolder.toString(), destinationParentFolder.toString());
Files.copy(t, Paths.get(destinationPath));
} catch (FileAlreadyExistsException e) {
//TODO do acc to business needs
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
allFilesPathStream.forEach(action);
} catch (FileAlreadyExistsException e) {
//file already exists and unable to copy
} catch (IOException e) {
//permission issue
e.printStackTrace();
}
}
一些可以理解的英語怎麼樣?什麼是錯誤? – XtremeBaumer
爲什麼你得到'user.home'的路徑?你想要的是當前目錄('.')。 – m0skit0
user.home是目的地或目標.. –