0

guys! I'm trying to append folder to user.home property. It working nice, while I'm using just one additional folder. But when I try to make another two additions (so it looks like user.home+folder1+folder2+folder3) it trows --- java.lang.IllegalArgumentException: Folder parameter must be a valid folder--- . My though that there is some restriction, but can't find out where.

    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;
    }}
  • please share the error log – Gaali Prabhakar Apr 08 '17 at 06:42
  • Caused by: java.lang.IllegalArgumentException: Folder parameter must be a valid folder at com.sun.glass.ui.CommonDialogs.convertFolder(CommonDialogs.java:238) at com.sun.glass.ui.CommonDialogs.showFileChooser(CommonDialogs.java:190) at com.sun.javafx.tk.quantum.QuantumToolkit.showFileChooser(QuantumToolkit.java:1496) at javafx.stage.FileChooser.showDialog(FileChooser.java:416) at javafx.stage.FileChooser.showSaveDialog(FileChooser.java:392) at ru.mlog.xmlread.gui.MainController.SaveToButton(MainController.java:142) ... 62 more – Максим Давидюк Apr 09 '17 at 12:06
  • print the System.out.print(fullRoute) , then check proper path are not if the path is ok then , the path is exited or not , if not exited create . then it ll work – Gaali Prabhakar Apr 10 '17 at 10:25
  • Yes, I already done it. It seems that path is ok, and folder is exists ( I even putted it in Main< in order to have a valid path) - in the end I got valid path printed, - C:\Users\mda\MLogg\ad\da - and, of course - Caused by: java.lang.IllegalArgumentException: Folder parameter must be a valid folder – Максим Давидюк Apr 11 '17 at 09:42
  • So, I was adviced to make a path and make dirs with different methods. So, I made a string with path and then make a check for .exists() and make folders of a whole path. So now it's all ok. Thanks for assistance! – Максим Давидюк Apr 11 '17 at 18:06

1 Answers1

0
 String fullRoute = null;
    File homeDir = new File(System.getProperty("user.home"));

    if (SiteCo.getValue() !=null && InciDate.getValue() !=null) {

        System.out.println(SaveVarTo.getMainFolder());
        fullRoute = homeDir + File.separator + SaveVarTo.getMainFolder() +
                File.separator + SiteCo.getValue().toString() + 
    File.separator + InciDate.getValue().toString();

    } else {
        fullRoute = homeDir.toString();
    }

    System.out.println(fullRoute);
    File fhd = new File(fullRoute);
    if (!fhd.exists())
        fhd.mkdirs();
    fileChooser.setInitialDirectory(fhd);
    fileChooser.getExtensionFilters().addAll(
            new FileChooser.ExtensionFilter("XML Files", "*.xml"));