Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2006

Tip: Looking for answers? Try searching our database.

how can i know user home dir from java applet

Thread view: 
nagesh_mandlem@yahoo.com - 09 Jan 2006 13:56 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.