Computing.Net > Forums > Programming > changing directory in java

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

changing directory in java

Reply to Message Icon

Name: priti
Date: March 5, 2004 at 19:44:41 Pacific
OS: WIn 2000
CPU/Ram: P3
Comment:

Hi,
I'm writting webserver and I want to change the directory.
How can I do this in java?
e.g I've working dir. /aaa/bb/t.txt
and I want to access fiel in dir /aaa/bc/p.txt
How could I do this?
Any help will be appreciated?
Thanks/



Sponsored Link
Ads by Google

Response Number 1
Name: wharfie
Date: March 10, 2004 at 15:52:18 Pacific
Reply:

I don't believe the working directory of your Java application can be changed so if it was /aaa/bb when you launched your Java application that is what it will stay.

There is no need to change it to access files in other directories as the java.io.File constructor takes a qualified file name which may include an absolute or relative path.

In the scenario you describe you would create the two files like this

// file in working directory
File tFile = new File("t.txt");

// file in another directory using relative path
File pFile = new File(".." + File.separator + "bc" + File.separator + "p.txt"0;

// access both files
FileInputStream tInputStream = new java.io.FileInputStream(tFile);
FileInputStream pInputStream = new java.io.FileInputStream(pFile);



0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: changing directory in java

NoClassDefFoundError in java www.computing.net/answers/programming/noclassdeffounderror-in-java/14090.html

phone list program in java www.computing.net/answers/programming/phone-list-program-in-java/8591.html

writing data to file in java www.computing.net/answers/programming/writing-data-to-file-in-java/14129.html