469,336 Members | 5,257 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Get current directory and set current directory.

dmjpro
2,476 2GB
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.
Mar 14 '08 #1
8 10748
sukatoa
539 512MB
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
Mar 14 '08 #2
JosAH
11,448 Expert 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(new File("fronobulax").getCanonicalPath());
  2.  
You do have to handle potential IOExceptions.

kind regards,

Jos
Mar 14 '08 #3
sukatoa
539 512MB
You don't even have to create a real file for that; an abstract pathname is enough:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(new File("fronobulax").getCanonicalPath());
  2.  
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...
Mar 14 '08 #4
JosAH
11,448 Expert 8TB
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
Mar 14 '08 #5
sukatoa
539 512MB
There's also the FileSystemView class but it's similar to the File() solution.

kind regards,

Jos

I got it...

Sukatoa...
Mar 14 '08 #6
dmjpro
2,476 2GB
You don't even have to create a real file for that; an abstract pathname is enough:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(new File("fronobulax").getCanonicalPath());
  2.  
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.
Mar 14 '08 #7
JosAH
11,448 Expert 8TB
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
Mar 14 '08 #8
dmjpro
2,476 2GB
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!
Mar 14 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by EAS | last post: by
11 posts views Thread by kk | last post: by
3 posts views Thread by Progman | last post: by
3 posts views Thread by Chris Mellon | last post: by
6 posts views Thread by titan.nyquist | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.