Reputation: 47
My project Structure like,
MyTest
|--> src
|--> .... all java codes...
|--> www
|--> myfile.txt
i tryed to solve it by Resource resource1 = new ClassPathResource("classpath:myfile.txt");
but it couldn`t find file. also i search it in Stackoverflow but no actual answer related to this.
how to i read contents of myfile.txt in my Test.java ?
any one have solution please share with me . Thanks !!
Upvotes: 0
Views: 1332
Reputation: 5566
If you are using a Maven as your build tool, you need to include your www
directory to the classpath in your pom.xml:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<directory>src/main/www</directory>
</resource>
</resources>
</build>
You can read more about it here.
Upvotes: 2
Reputation: 28
The file is in the class path folder then it will work. classpath: filename is not needed. Just give the file name as parameter
Upvotes: 0
Reputation: 133
You are using what IDE? If you are using IntelliJ , you should set the containing folder of your file as resources
Upvotes: 0