sk_25
sk_25

Reputation: 48

File Constructor can not read file in RestFull webservice

File jarFile = new File("src/test/java/Draft.jar");
if ((jarFile).exists()) {

System.out.println("Jar file exists");

} 
else {

   System.out.println("Jar file not exists");

}

jar is present in that location but it's not run properly every time it prints "Jar file not exists"

Upvotes: 1

Views: 53

Answers (1)

flyingfox
flyingfox

Reputation: 13506

You need avoid put files inside src/test location,since when you compile your code,it might clean the files

For your question,two ways to debug it:

a. make the jar file in another location,not src/test,you can change to src/resources,in fact,you had better not put file inside src folder. Also you need to make sure the file path is correct,sometimes you need to add .. / to get the right path

b. use absolute path instead of relative path,such as below:

File jarFile = new File("D://Draft.jar");

Upvotes: 1

Related Questions