0

I want to use my manifest.mf file as an InputStream so I can retrieve some of the data that is inside. I use the following line of code:

inputStream = new FileInputStream("../../../../WebContent/META-INF/MANIFEST.MF");

Because the java class and the manifestfile are located in the following directory:

enter image description here

Unfortunately, this path always give me a FilenotFoundException. What is the correct path to refererence this file?

user1884155
  • 3,616
  • 4
  • 55
  • 108

2 Answers2

1

try this:

File file = new File("../../../../WebContent/META-INF/MANIFEST.MF");
System.out.println(file.getCanonicalPath());

see where your app think the file is located and fix the path

Алексей
  • 1,847
  • 12
  • 15
1

You want to load a file that is bundled with your web application application. This file will be part of the war file of your deployed app. It thus won't be on the file system. So loading it with a FileInputStream is not the right solution.

BTW, file paths are not relative to the class creating the FileInputStream. They're relative to the directory from which the application server is launched.

The way to load webapp resources is to use the ServletContext.getResourceAsStream() method. Read its javadoc (and the javadoc of ServletContext.getResource()) carefully.

You should also realize that WebContent is the name of the directory where the sources of your webapp are. Once packaged and deployed on a server, there won't be any WebContent directory anymore.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255