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 / General / January 2006

Tip: Looking for answers? Try searching our database.

how can i know home directory from java

Thread view: 
Nagesh - 09 Jan 2006 13:28 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. 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
Thomas Weidenfeller - 09 Jan 2006 13:54 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.

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

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



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.