File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to change directory Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "How to change directory" Watch "How to change directory" New topic
Author

How to change directory

richard Jei
Greenhorn

Joined: Jan 29, 2001
Posts: 3
Since File class cannot be used to change the current working directory, can anyone tell me which class can be used to change the current working directory to specified directory.
Thanks in advance!
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
You use the File class and the list() method along with isDirectory or isFile to find what you want. If it's a directory, then you create another File object to move to the new directory. Not very elegant, but that's the only way.
-Peter
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Hello,
I am a greenhorn, but I believe you cannot in one command change a default directory. There may be other options depending on what you want to do.
For example:
I Create another directory with a copy of the file you want.
1. Copy the existing file
2. Save a copy of the file in the area that you want to save
it. If no directory already exists that create one with
the mkdir command.
II. Refer to the file that you want to use with the file path
name and the string name.
public File(String directoryPath, String filename)

III. Refer to the directory where the file is wanted:
public File(String directory Path)
I hope this helps, if you need more info let me know.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to change directory
 
Similar Threads
Can't read a file
Assertion Doubt 1
Runtime problem in Command Prompt
how to change current (working) directory?
Javac:File Not Found