wood burning stoves 2.0*
The moose likes Java in General and the fly likes go to a specific directory (Runtime.getRuntime();) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "go to a specific directory (Runtime.getRuntime();)" Watch "go to a specific directory (Runtime.getRuntime();)" New topic
Author

go to a specific directory (Runtime.getRuntime();)

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi all,

Im trying to refer to a specific folder in my file system (yes, i know the path :-) )
for some reason when I use:



it doesn't take me to the specific folder.

the path in this example is: C:\Tomcat\webapps

anyone?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Are you trying to set the working (current) directory for the JVM process? You can't do that. But you really shouldn't need to -- what is your actual requirement?


[Jess in Action][AskingGoodQuestions]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
I have a file there and I need to copy it to a different directory.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Open it with a FileInputStream
Open the new location with a FileOutputStream
Allocate a byte array buffer
Read into the buffer, write from the buffer
close both streams.
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
I need to do it (the copy) with the DOS command.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

The Runtime.getRuntime().exec() method is overloaded with a version that lets you set the current working directory.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
In JDK 5 see also ProcessBuilder.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: go to a specific directory (Runtime.getRuntime();)