how can i know home directory from java

N

Nagesh

I want to know user home directory when i run through java applet. I
could not success through System.getProperty("user.home") as it gave me
security exception. Then i tried the following way which simply exec
the commands "echo %HOMEDRIVE%%HOMEPATH%" for windows and for linux
"echo $HOME". But this also fails as it is giving me the exception
java.io.IOException: CreateProcess: echo %HOMEDRIVE%%HOMEPATH% error=2
and java.io.IOException: CreateProcess: echo %HOMEDRIVE%%HOMEPATH%
error=2. what these errors mean?
is there any other way of knowing home directory in platform neutral
way?

I tried the following souce code.

import java.applet.* ;
import java.io.*;
public class execOutput extends Applet{
public void init(){
}
public void start(){
String envoutput=readenv();
}
String readenv(){

String env="echo %HOMEDRIVE%%HOMEPATH%";
try {
String ls_str;
Process ls_proc = Runtime.getRuntime().exec(env);
// get its output (your input) stream
DataInputStream ls_in = new DataInputStream(

ls_proc.getInputStream());
try {
while ((ls_str = ls_in.readLine()) != null) {
return ls_str;
}
} catch (IOException e) {
System.out.println("Exception in
environmental output"+e);
}
} catch (IOException e1) {
System.out.println("Exception in
environmental output"+e1);

env="echo $HOME";
}
try {
String ls_str;
Process ls_proc = Runtime.getRuntime().exec(env);
// get its output (your input) stream
DataInputStream ls_in = new DataInputStream(

ls_proc.getInputStream());
try {
while ((ls_str = ls_in.readLine()) != null) {
return ls_str;
}
} catch (IOException e) {
System.out.println("Exception in
environmental output");
}
} catch (IOException e1) {
System.out.println("Exception in
environmental output"+e1);
env="echo $HOME";

}
return "not found";
}
}

thanks
Nagesh
 
T

Thomas Weidenfeller

Nagesh said:
I want to know user home directory when i run through java applet. I
could not success through System.getProperty("user.home") as it gave me
security exception.

Please don't multipost, this is considered rude on Usenet. You question
has been answered in another group already.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top