In a cofiguration file i am specifying a bean and its constructor. but i am getting FILE NOT FOUND EXCEPTION

<bean name="FileReader" class="java.io.FileReader">
            <constructor-arg index="0">
                  <value>c:/rad/translator/src/resources/sampledata/member.lst</value>
            </constructor-arg>            
      </bean>      

I am having 'File not found error". Could anyone suggest me where i went wrong
cutie_smilyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunray_2003Commented:
You can verify whether the file exists in the location  c:/rad/translator/src/resources/sampledata/member.lst mentioned in your configuration file. Btw, is it member.lst or txt? Also you can escape character to the file pah C:\\rad\\...
0
ragerinoCommented:
i've tested it and it worked properly.
i used this applicationContext.xml.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="
                  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
                  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

      <bean name="FileReader" class="java.io.FileReader">
            <constructor-arg index="0">
                  <value>c:/temp/test.txt</value>
            </constructor-arg>
      </bean>

</beans>

this is the output:
Cp1252

when i changed the path to the file to a non-existing file i got this Exception:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FileReader' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.io.FileReader]: Constructor threw exception; nested exception is java.io.FileNotFoundException: c:\temp\testx.txt

below is the code of my testapp
import java.io.FileReader;
import java.io.IOException;
 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 
public class Test {
 
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		ApplicationContext appCtx=new ClassPathXmlApplicationContext("applicationContext.xml");
		FileReader reader=(FileReader)appCtx.getBean("FileReader");
		
		System.out.println(reader.getEncoding());
		reader.close();
 
	}
 
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sunray_2003Commented:
Your application is working as epected. When a file reader cannot find a file, it throws an Exception. And if the file is present it reads and processes it properly. There is no problem that I could see in your code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.