Results 1 to 2 of 2

Thread: os path

  1. #1
    Join Date
    Oct 2009
    Posts
    88
    Rep Power
    0

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    Other than interpreting the things in the "java.class.path" java environment (system property) variable, like to try to guess the "C:" parts if there are any, there is no built-in Java property to say what the operating system installation drive is.

    Nor, is there any built-in way to read the system environment variable settings. Also note that the os "installed drive" is specific to Windows operating systems.

    You can try setting your own -DOS_INSTALL_DRIVE=%SYSTEM_ROOT% in the Java command line or batch file that launches your application, where in this example the %SYSTEM_ROOT% thing would be an environment variable [you] set up ahead of time, or possibly what ever environment variable that comes set with windows.

    I generally use the following utility to sniff out all the currently set Java environment properties.
    Java Code:
    import java.util.Map;
    import java.util.Properties;
    import java.util.TreeMap;
    
    /**
     * Prints a sorted list of system properties to the stdout.
     * @author thein
     *
     */
    public class DumpSystemProperties {
    
        public static void main(String[] args) {
            
            Properties p = System.getProperties();
            Map<String, String> sortedProperties = new TreeMap<String, String>();
            for (Object key : p.keySet()) {
              sortedProperties.put(key.toString(), p.getProperty(key.toString()));
            }
            for (String key: sortedProperties.keySet()) {
              System.out.println(key  + ":" + sortedProperties.get(key));
            }
        }
    }

Similar Threads

  1. how to set path ?
    By Emy in forum Advanced Java
    Replies: 2
    Last Post: 10-07-2009, 07:32 AM
  2. server path
    By gokul119 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-09-2009, 03:51 AM
  3. Where should this path be?
    By Abder-Rahman in forum Advanced Java
    Replies: 1
    Last Post: 02-16-2009, 07:13 AM
  4. trying to get class name & path
    By sandor in forum New To Java
    Replies: 4
    Last Post: 08-12-2008, 01:38 PM
  5. Specify path
    By borgrodrick in forum Eclipse
    Replies: 1
    Last Post: 02-12-2008, 11:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •