• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a file there and I need to copy it to a different directory.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to do it (the copy) with the DOS command.
 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Runtime.getRuntime().exec() method is overloaded with a version that lets you set the current working directory.

Henry
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JDK 5 see also ProcessBuilder.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic