5 Replies Latest reply: Nov 21, 2012 6:43 AM by TPD-Opitz RSS

    How to get Folder Location by just providing folder name ?

    Ajay Sharma
      Hi,

      I want to get folder location by providing its name.

      I created one folder on "E:\" drive and when I used following code in netbeans it giving me the current loaction of java file.
      File directory = new File("SVN");
              boolean isDirectory = directory.isDirectory();
              if (isDirectory) {
                  // It returns true if directory is a directory.
                  System.out.println("the name you have entered is a directory  : "  +    directory);  
                  //It returns the absolutepath of a directory.
                  System.out.println("the path is "  + directory.getAbsolutePath());
              }
              else {
                  // It returns false if directory is a file.
                  System.out.println("the name you have entered is a file  : " +   directory);
                  //It returns the absolute path of a file.
                  System.out.println("the path is "  +  directory.getAbsolutePath());
              }
          }
      And i got following output
      the name you have entered is a file  : SVN
      the path is C:\Users\AjayS\Documents\NetBeansProjects\TestCodes\SVN
      But my folder is located on "E:\" drive.

      Regards,
      Ajay