Hi,
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";
}
}
if any body knows the solution,
pls let me know
nagesh.
Albert Oppenheimer - 09 Jan 2006 16:09 GMT
Java applications can access the local file system.
Java applets cannot. This is a very basic matter of Internet security.
> Hi,
> I want to know user home directory when i run through java applet. I
[quoted text clipped - 75 lines]
> pls let me know
> nagesh.
Roedy Green - 09 Jan 2006 17:09 GMT
>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.
the thinking is you have no business knowing since a unsigned Applet
has no permission to write to the local hard disk. You must sign your
applet.
See http://mindprod.com/jgloss/signedapplets.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.