How to get file path dynamically?

marzie

I write an application that load other classes from other folder like so :

public static void main(String[] args) throws Exception
{
    String rootPath = null;
    rootPath = System.getProperty("user.dir");
    //System.out.println(rootPath);

    File operatorFile = new File(rootPath + "Business\\");
    URL operatorFilePath = operatorFile.toURL();
    URL[] operatorFilePaths = new URL[]{operatorFilePath};
    ClassLoader cl = new URLClassLoader(operatorFilePaths);

    // Plus , Minus,Multiply,Divide are classes in Business folder
    Class[] operatorClass = new Class[]{ cl.loadClass("Plus"), cl.loadClass("Minus"),cl.loadClass("Multiply") , cl.loadClass("Divide")
};

I Want Dynamically get the Business folder path(My main class is in MyFolder). Both MyFolder and Business folders are in drive D:\ . But this app dose not work because I think below statement dose not correct :

File operatorFile = new File(rootPath + "Business\\");

Can anyone help me?

Anand Dwivedi

Since you Have to Remeber Some Points .

  • Where you Home Drive Pointed :System.getProperty("user.home");//Either C or D whatever .

or :

 rootPath = System.getProperty("user.dir")+System.getProperty("file.separator")+"Business";

or

  String  rootPath = System.getProperty("user.dir")+System.getProperty("file.separator")+"D"+System.getProperty("file.separator")+"MyFolder";
  rootPath=rootPath.replaceAll("MyFolder", "");//Remove MyFolder from URL
  rootPath=rootPath+"Business";//Add Business on URL
   System.out.println(""+rootPath);//Print File Path

that will Return your Home Directory With Business Folder

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Inno Setup (How to get dynamically path to file)?

From Dev

How to get file path?

From Dev

How to set file path dynamically in Java program?

From Dev

How can I get the path of a module dynamically?

From Dev

How can I get the path of a module dynamically?

From Java

How to get full path of a file?

From Dev

How to get .ipa file path

From Dev

How to get path of file with batch

From Dev

how to drag a file and get path of it

From Dev

How to get the file path of a buffer?

From Dev

How to get path of file with batch

From Dev

How to get path of a file in windows

From Dev

How to split a file path to get the file name?

From Dev

How to dynamically get the directory of the file running

From Dev

How can I get path to current twig template dynamically?

From Dev

How to get spring boot application jar parent folder path dynamically?

From Dev

JimFS: how to get File from Path

From Dev

How to get file path from JavaFX FileChooser?

From Java

How to get the path of a running JAR file?

From Java

How to get an absolute file path in Python

From Dev

How to get the right file path in Servlet program?

From Dev

How to get the file path location of a .jar dependency?

From Dev

How to get asset file path in Xamarin?

From Dev

How to get file path to show on Netbeans tab

From Dev

How To Get Real Path Of A File Using Jquery

From Dev

how to get file path of asset folder in android

From Dev

How to get path in spring to access configuration file

From Dev

How to get accurate path of the uploaded file in jsp?

From Dev

ContentResolver -- how to get file path of attachment