Quick question (I think...Ihope)

I'm trying to do something I thought was simple, but apparently it's not simple enough.

I'm on linux and I'm trying to write files to the current user's /home directory? Anyone know how I can do this? I was looking into System.getProperties.. but I'm not getting anywhere. Any tip would be greatly appreciated. Thanks --Chris

[344 byte] By [javverjaw] at [2007-9-30 23:27:30]
# 1
System.getProperty("user.home") should give the user's home directory.
jverd at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...
# 2

Thank you sir.That doesn't seem to be working for me...am I missing something here?The following doesn't print anything:

import java.util.*;

public class ShowProps {

public void ShowProps() {

System.out.println(System.getProperty("user.home"));

}

public static void main(String[] args) {

ShowProps thisProps = new ShowProps();

}

}

javverjaw at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...
# 3
Try System.getProperties().list(System.out);
Peter-Lawrey at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...
# 4

From the API for "System.getProperties()"

The current set of system properties for use by the getProperty(String) method is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties always includes values for the following keys: Key Description of Associated Value

java.versionJava Runtime Environment version

java.vendorJava Runtime Environment vendor

java.vendor.urlJava vendor URL

...

user.homeUser's home directory

javverjaw at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...
# 5
Nada.. What the heck
javverjaw at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...
# 6
The problem is what you think is a constructor is not. Having "void" makes it just a method that has the same name as the class. Constructors don't have a return type. So you've just got the implicit default constructor, which does nothing. Get rid of "void".
jverd at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...
# 7

> The problem is what you think is a constructor is

> not. Having "void" makes it just a method that has

> the same name as the class. Constructors don't have a

> return type. So you've just got the implicit default

> constructor, which does nothing. Get rid of "void".

On the ShowProps method/constructor-wannabe that is, not on main.

jverd at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...
# 8
You da man. Thanks so much. That would've taken me wayyy to long to figure out (if ever...I'd have kept focussing on the Properties stuff)
javverjaw at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...
# 9
I was scratching my head for a while too. :-)It's a pretty common mistake though. I actually wish Java didn't allow regular methods to have the same name as the class. There's no good reason to do so, and it just leads to confusion with ctors.
jverd at 2007-7-7 14:03:15 > top of Java-index,Security,Event Handling...