• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

how to get the current directory name?

Hi,
a) i am using netbeans ide3.6, my application is stored in d:/temp when i use

String s=system.getProperty("user.dir");

it still refers to " C:\Programme\NetBeans3.6\jakarta-tomcat-5.0.19\bin" intead of displaying my current directory as "d:/temp".

b) how to calculate the cache size of the current directory(in this case for the directory "d:/temp").
Thanx.
0
vihar123
Asked:
vihar123
  • 7
  • 5
  • 5
  • +3
1 Solution
 
objectsCommented:
> intead of displaying my current directory as "d:/temp".

d:\temp is not the current directory.
If you want it to be the current directory then tell netbeans to run your application from that directory

> b) how to calculate the cache size of the current directory(in this case for the directory "d:/temp").

If you mean the total size of files in that directory then use listFiles() to loop thru all the files in the directory and sum the file sizes.
0
 
vihar123Author Commented:
can u tell me how to tell the netbeans  d:/temp as my current directory.
0
 
objectsCommented:
look at your project properties and change the working directory
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
vihar123Author Commented:
hi,

i am using netbeans 3.6.
sorry i didnot found project properties.
can you tell me where exactly it locates'?
0
 
objectsCommented:
sorry i've only got 4 running here.

don't you have a properies option when u right click on the project?
how do u currently change any properties of your projects
0
 
vihar123Author Commented:

I dont know exactly.
if u know later pls reply.
until now i have not changed the properties of the working directory.

0
 
objectsCommented:
do you not have a properties option in the menu when u right click on your project?
0
 
objectsCommented:
have alook at the Options window in 3.6
0
 
sciuriwareCommented:
Do not set your working directory from Netbeans, or your application
will never run anywhere else ..........................
<*>
0
 
vihar123Author Commented:
i have not set the any thing just installed and using it.
0
 
objectsCommented:
no the point is you should write code that expects the current directory to be a specific place because it will be different depending on where the user runs your code from.
If you specifically want to use that directory d:\temp then use that explicitly in your code.

System.getProperty("user.home") is another possibility

0
 
sciuriwareCommented:
I agree with the genius^3 :
1) use the user.home property as a (local) starting point of your data-tree
    (at least, you should have your things organised),
2) use a fixed position, not always good, but at least independent of the place where
    your program runs from, or if it is a collection of classes or .jar bundle,
3) use your own properties file or your own 'Registry' to be able to
     specify "where my things are on this system".
The latter is portable and deliverable to a user/customer.
<*>
0
 
gnoonCommented:
       File currentDirectory = new File("");

        String currentDirectoryName = currentDirectory.getAbsoluteFile().getName();

        System.out.println("Current Path: "+currentDirectory.getAbsolutePath());
        System.out.println("Directory Name: "+currentDirectoryName);
0
 
sciuriwareCommented:
Yes that's always the same as System.getProperty("user.dir")
and unreliable as stated before.

You might wonder why there's no     'chdir()'    in JAVA .....
... it's because JAVA is multi-threading.
What would happen if one thread changed the current directory,
while other threads still depend on the previous settings?   DISASTERS!
<*>
0
 
rama_krishna580Commented:
0
 
vihar123Author Commented:
I tried with System.getProperty("user.home") but that refers to c:/documents and settings/myname ,
the problem is still not solved, with all the above suggestions.

any clarification in the question kindly let me know.

0
 
objectsCommented:
> I tried with System.getProperty("user.home") but that refers to c:/documents and settings/myname

yes thats where its meant to point :)

> the problem is still not solved, with all the above suggestions.

You need to change where the program is run from as already suggested.
Though anyone running your program will also need to run the application from the same directory.
0
 
sciuriwareCommented:
c:/documents and settings/myname
is your private area; there you should store the actual properties (pathnames) to data and applications.
<*>
0
 
TrigunaCommented:
Make one file object by passing file path as argument:

File currentFile = new File("d:/temp");

with this file object you can get the file lists, file names in side the directory and so on.

hope this will help u.
0
 
sciuriwareCommented:
That is no solution at al.

;JOOP!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 7
  • 5
  • 5
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now