Listing 9: PropTest.java — Illustrates common file-related system properties

class PropTest
{
    static void displayProperty(String name)
    {
        String prop = System.getProperty(name);
        System.out.println(name + ": " + "\"" + prop + "\"");
    }

    public static void main(String[] args)
    {
        displayProperty("file.separator");
        displayProperty("path.separator");
        displayProperty("user.name");
        displayProperty("user.home");
        displayProperty("user.dir");
        displayProperty("line.separator");

        // Display bytes of line.separator:
        String lineSep =
            System.getProperty("line.separator");
        byte[] bytes = lineSep.getBytes();
        for (int i = 0; i < bytes.length; ++i)
            System.out.print(bytes[i] + " ");
        System.out.println();
    }
}

/* Output:
file.separator: "\"
path.separator: ";"
user.name: "Administrator"
user.home: "C:\Documents and Settings\Administrator"
user.dir: "C:\CUJ"
line.separator: "
"
13 10 
*/
— End of Listing —