伙计们!我正在尝试将文件夹附加到 user.home 属性。它工作得很好,而我只使用了一个额外的文件夹。但是当我尝试添加另外两个添加项(所以它看起来像 user.home+folder1+folder2+folder3)时,它会抛出 --- java.lang.IllegalArgumentException: Folder parameter must be a valid folder--- 。我虽然有一些限制,但找不到在哪里。
String fullRoute = null;
File homeDir = new File("MLog");
if (!SiteCo.getEditor().getText().isEmpty() &&
!InciDate.getEditor().getText().isEmpty()) {
homeDir.mkdirs();
fullRoute = System.getProperty("user.home") + File.separator +
//SaveVarTo.getLastVisitedDirectory() +
SaveVarTo.AddPath(SiteCo.getValue().toString()) +
File.separator + SaveVarTo.AddPath(InciDate.getValue().toString());
}
else {homeDir.mkdirs();
// File.separator+homeDir.toString() - without it
fullRoute =
System.getProperty("user.home")+File.separator+homeDir.toString();}
System.out.println(fullRoute);
fileChooser.setInitialDirectory(new File(fullRoute));
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("XML Files", "*.xml"));
//sample of method
public class Variables{
public String AddPath(String name) {
if (!name.isEmpty()) {
//File nou = new File(getLastVisitedDirectory() +"\\" + name);
File nou = new File(name);
if (!nou.exists()) {
nou.mkdirs();
} else {
System.out.println("Folder already exists");
}
}
else{name = null;}
return name;
}}