Link to home
Start Free TrialLog in
Avatar of _Esam
_Esam

asked on

getResourceAsStream Error?

Hi,
I am trying to parse an XML file using a custom XML parser.
But I am just not even being able to read it ???

I have CECEVFeedConfigParameters class that uses the parser, and in it I tried:
  InputStream lConfigFileInputStream =
                ((Class)mClass)
                    .getResourceAsStream
                        (CEC_EV_FEED_CFG_FILE);

            if (lConfigFileInputStream == null)
            {
                throw new TransferSystemException
                    ("CEC EV Feed config file "+
                     CEC_EV_FEED_CFG_FILE +
                     " missing");
            }

I have an Interface where I declared:
 public static final String
        CEC_EV_FEED_CFG_FILE            = "C:\\Projects\\CECEVFeedConfigParameters.xml";

In my main class I tried as:

File            lCECEVFeedFilePath      = null;
try{
            lCECEVFeedFilePath =
                      new File(CECEVFeedConfigParameters.getInstance().getDataFilePath());
                        
                  }
                  catch(Exception e){
                        e.printStackTrace();
                        System.out.println("Could not parse");
                        
                  }

And I get the error:

null

.........................TransferSystemException printStackTrace:

.........................TransferSystemException: CEC EV Feed config file C:\Projects\CECEVFeedConfigParameters.xml missing
      at ............util.CECEVFeedConfigParameters.getInstance(CECEVFeedConfigParameters.java:123)
      at .............EmailMain.read(EmailMain.java:35)
      at ..............EmailMain.main(EmailMain.java:101)

...................................TransferSystemException: 0

Imbedded Exception   = java.lang.Exception
Imbedded Exception
           message   =

Fri Jun 02 01:40:32 CDT 2006
5
2
5
Here
Could not parse


I NEED TO KNOW WHAT I NEED TO DO SO THAT I CAN READ THE XML FILE ..... (NOT TO THINK ABOUT PARSING NOW :)

I AM JUST RUNNING THE APP WITH ECLIPSE ..
DO I NEED TO SET UP THE CLASSPATH ??? FOR THE RESOURCE???
NEED A SOLUTION ......(FULL POINTS DUE TO ........)

LET ME KNOW..

Thax.
_Esam
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try


InputStream lConfigFileInputStream = new FileInputStream(CEC_EV_FEED_CFG_FILE);
Avatar of _Esam
_Esam

ASKER

I get what you are trying to say....

But..
I have to use it as I tried to illustrated it:

How do I put it in the CLASSPATH then? (Using Eclipse:)

_Esam
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> How do I put it in the CLASSPATH then? (Using Eclipse:)

put it in the same directory as the class file and use the command I posted above
Avatar of _Esam

ASKER

Eventually I will have to use the custome parser to parse through the XML and get the attributes...
I just want to test that I can at least read it using the getResourceAsStream() - this I have to use :)

_Esam
> I just want to test that I can at least read it using the getResourceAsStream() - this I have to use :)

See my earlier comment, it shows what you need to do to use getResourceAsStream()

For example if u put it in the same directorory as mClass you would use:

 InputStream lConfigFileInputStream =
                ((Class)mClass)
                    .getResourceAsStream
                        ("CECEVFeedConfigParameters.xml");


Avatar of _Esam

ASKER

> InputStream lConfigFileInputStream =
                ((Class)mClass)
                    .getResourceAsStream
                        ("CECEVFeedConfigParameters.xml");

Yes -- I just wanted to use the final variable ?
Anyway,
It is working if I put it in the same directory now....
Just getting my expected error now... Happy with it so far..
But trying to put it in a different directory and try it now ... and getting back soon...

Thanks.
_Esam
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _Esam

ASKER

>Your binaries and config files should be logically separated so shouldn't be in the same directory

Indeed  that's what I was planning but I needed to make sure that for the least I can make it work :)

It's working both ways now.. If I put it in the same directory of the class file or in a different directory relative to the current working directory..

Thanks both...

Coming back shortly with a parsing problem... :)

_Esam.
:-)