0

I am using Spring MVC + JDBC to make a web-app, and i've created a DAO Class to handle queries. My problem is this: I have this really big query, and I would like to keep it in a .txt file and read the query inside the DAO, but I keep getting java.io.FileNotFoundException. Where should I put my .txt with my queries? I've tried to store it in the same class as the DAO, but it didn`t work.

I`m a complete beginner when it comes to use Spring MVC, and I have installed the SprigSource Tool Suite, so everything is pre-configured.

Can someone help me with this issue?

Thank you!

Cesar Vargas

https://i.stack.imgur.com/fBNpV.png

https://i.stack.imgur.com/jXu1K.png

cesarvargas
  • 182
  • 3
  • 15
  • 1
    You really should tell us about the details, e.g. where did you place the file, how does the relevant part of your code look like? – home Jun 17 '12 at 05:58
  • Well, i've tried to store the file in the same folder as the DAO. I erased all the bad code, so Ill have to do it again, then ill post here. – cesarvargas Jun 17 '12 at 22:47

1 Answers1

0

Try:

InputStream is = getClass().getResourceAsStream("queriesCountJava.txt");

which looks for the file on the classpath.

nickdos
  • 8,348
  • 5
  • 30
  • 47
  • Thank you! Works like a charm. But i have a doubt: is there any other way to read data different than `.readLine()` method? In Eclipse, it says it`s deprecated! – cesarvargas Jun 18 '12 at 03:17
  • http://stackoverflow.com/questions/5611387/datainputstream-deprecated-readline-method – nickdos Jun 18 '12 at 03:50