Thanks for the response, Miga.
I tried what you suggested and I was still getting the File Not Found
exception. But then, in my looking around on the Web, I found a
tutorial for FileInputStream that showed placing the call inside of a
try-catch block. I tried that and now the program loads and runs.
Here's the code I now have:
import java.io.FileInputStream;
import java.util.Properties;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
*
* @author Eric
*/
public class SetSystemProperties {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// set up new properties object
// from file "myProperties.txt"
FileInputStream propFile = null;
try {
propFile = new FileInputStream("myProperties.txt");
} catch (FileNotFoundException e) {
System.out.println("Whoops");
}
Properties p = new Properties(System.getProperties());
try {
p.load(propFile);
} catch (IOException e) {
System.out.println("Whoops");
}
Not sure why it needed the try-catch blocks but, hey, it works now.
Thanks again for the help!
Eric
On Mon, Feb 16, 2009 at 12:03 PM, miga <[email protected]> wrote:
>
>
>
> On Feb 16, 5:44 pm, InfinityLtd <[email protected]> wrote:
>> Hello all.
>>
>> I followed along with the instructions in the lab for this part to
>> create and read the myProperties.txt file. I'm using NetBeans 6.5. I
>> created the file through NetBeans and found that it saved the file in
>> the project folder ("...\SetSystemProperties\myProperties.txt"). When
>> I tried to build the program, I got a "File Not Found" exception. I
>> checked all of the code and it matched the text in the exercise. So I
>> tried moving the myProperties.txt file into the src folder within the
>> project to be with the .java file, but the program threw the exception
>> again. I even tried putting in the full path and filename ("k:/.../
>> myProperties.txt") but it still couldn't find it. Where is the text
>> file supposed to reside or is there some other method to tell Java
>> where to look for the text file?
> You may place it in various places, providing that you give the
> relative url to the top of the project to find it in the program.
> So, you may place it (as it is done in the sample) just under the
> project folder, in this case, just give the name of the file. To move
> it properly use the Files tab in Netbeans.
> You may also place it inside the same package as the java source. This
> can be done inside Netbeans and in this case you should give as url:
> src/myProperties.txt providing that you have not defined a named
> package. If you have defined a named package, then the url is src/
> nameofthepackage/myProperties.txt.
> And so on.
> >
>
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---