Hi Ricardo,

Try the following code :

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class SetSystemProperties {

        public static void main(String[] args) throws IOException  {
                FileInputStream propFile = null;
                try {
                        propFile = new 
FileInputStream("myProperties.txt");\\Please specify
your file path here
                        Properties p = new Properties();
                        p.load(propFile);
                        p.setProperty("myKey1", "myValue1");
                        System.out.println(p.getProperty("subliminal.message"));
                        System.out.println(p.getProperty("myown.property"));
                        System.out.println(p.getProperty("myKey1"));
                        throw new IOException(); // I added this code to throw 
an
IOException explicitly , remove this for your code.This
                                                             // is
just for showing how exception is caught
                        } catch (FileNotFoundException e) {
                        System.out.println("File not found in the place");
                        e.printStackTrace();
                } catch (IOException e) {
                        System.out.println("IO Exception Occured");
                        e.printStackTrace();
                } catch (Exception e) {
                        System.out.println("Some exception has occured");
                        e.printStackTrace();
                } finally {
                        if (propFile != null) {
                                System.out.println("Closing FileInputStream");
                                propFile.close();
                        } else {
                                System.out.println("FileInputStream not open");
                        }
                }
        }
}

which defines the code which handles specific exceptions and also
closes the File stream opened.
Remember for an application that reads / writes files its more
important to close your streams.

Thanks,
Ashok A V

On Sat, Aug 1, 2009 at 12:04 AM, Mauricio Murillo<[email protected]> wrote:
>
> Hi Ricardo,
>
> You're not catching your exception. Try this:
>
> ....
>
> try {
>
>  FileInputStream propFile = new ...
>
>   // The rest of your code
>
> } catch(Exception e) {
>  e.printStackTrace();
> }
>
> ....
>
> Greetings,
>
>
> On Jul 31, 12:28 pm, Ricardo Hernandez Rivera
> <[email protected]> wrote:
>> Hi all,
>>
>> Could you tell me why my FileInputStream objects get the fault showed in
>> the attachment.
>>
>> You can see the txt file is found in the place indicated by the lab. I'm
>> using Netbeans 6.5 on Linux Ubuntu 9.04.
>>
>> The sample downloaded from javapassion site works perfectly fine but the
>> same created by my own doesn't it.
>>
>> Please, someone help me... soon it's coming IO Basic lessons and I will
>> be not ready.
>>
>> Thanks in advance,
>> Ricardo
>>
>>  FileInputStream_error.jpg
>> 179KViewDownload
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to