Get current directory and set current directory.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Get current directory and set current directory.

    How do I get current directory in JAVA?
    And how do I set Current Directory in JAVA?

    When JVM runs a class file then what is it's current directory?
    Is it the JVM running path???

    Please help!

    Debasis Jana.
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by dmjpro
    How do I get current directory in JAVA?
    And how do I set Current Directory in JAVA?

    When JVM runs a class file then what is it's current directory?
    Is it the JVM running path???

    Please help!

    Debasis Jana.
    I have little doubt about your question...

    Would it mean that you like to know the current directory of your program/file?

    If this is what you mean,

    Just create a file(tempfile maybe) and get its AbsolutePath(). ...

    Since the returned string represents the file you have created (with its dir.)...
    Just remove that filename... ( the last )....

    If this is not what you mean,

    Update us...
    Sukatoa

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by sukatoa
      I have little doubt about your question...

      Would it mean that you like to know the current directory of your program/file?

      If this is what you mean,

      Just create a file(tempfile maybe) and get its AbsolutePath(). ...

      Since the returned string represents the file you have created (with its dir.)...
      Just remove that filename... ( the last )....

      If this is not what you mean,

      Update us...
      Sukatoa
      You don't even have to create a real file for that; an abstract pathname is enough:

      [code=java]
      System.out.prin tln(new File("fronobula x").getCanonica lPath());
      [/code]

      You do have to handle potential IOExceptions.

      kind regards,

      Jos

      Comment

      • sukatoa
        Contributor
        • Nov 2007
        • 539

        #4
        Originally posted by JosAH
        You don't even have to create a real file for that; an abstract pathname is enough:

        [code=java]
        System.out.prin tln(new File("fronobula x").getCanonica lPath());
        [/code]

        You do have to handle potential IOExceptions.

        kind regards,

        Jos
        Ohh, thanks for reminding.... yah, your right...

        Jos, for example, i have a class that was executed by JVM...

        Can i get the directory were my executed class exists without using file?
        I mean File Class?

        Is it possible?

        Or that was the last option?!!


        Sukatoa...

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by sukatoa
          Ohh, thanks for reminding.... yah, your right...

          Jos, for example, i have a class that was executed by JVM...

          Can i get the directory were my executed class exists without using file?
          I mean File Class?

          Is it possible?

          Or that was the last option?!!


          Sukatoa...
          There's also the FileSystemView class but it's similar to the File() solution.

          kind regards,

          Jos

          Comment

          • sukatoa
            Contributor
            • Nov 2007
            • 539

            #6
            There's also the FileSystemView class but it's similar to the File() solution.

            kind regards,

            Jos

            I got it...

            Sukatoa...

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by JosAH
              You don't even have to create a real file for that; an abstract pathname is enough:

              [code=java]
              System.out.prin tln(new File("fronobula x").getCanonica lPath());
              [/code]

              You do have to handle potential IOExceptions.

              kind regards,

              Jos
              Thank you JOS ...but If I want to change that path then is it possible?

              Debasis Jana.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by dmjpro
                Thank you JOS ...but If I want to change that path then is it possible?

                Debasis Jana.
                I wrote you that already: set the "user.dir" property in the system properties.
                Please read some relevant stuff first and only then ask: it's all in the File API
                documentation. Here is my previous post.

                kind regards,

                Jos

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by JosAH
                  I wrote you that already: set the "user.dir" property in the system properties.
                  Please read some relevant stuff first and only then ask: it's all in the File API
                  documentation. Here is my previous post.

                  kind regards,

                  Jos

                  Thanks a lot!

                  Debasis Jana!

                  Comment

                  Working...