You seem to be storing your CSS file in the classpath for some unobvious reason. The folder name src
is typical as default name of Eclipse's project source folder. And that it apparently magically works as being a relative path in the File
constructor (bad, bad), only confirms that you're running this in the IDE context.
This is indeed not portable.
You should not be using File
's constructor. If the resource is in the classpath, you need to get it as resource from the classpath.
InputStream input = getClass().getResourceAsStream("/main/webapp/resources/styles/some.css");
// ...
Assuming that the current class is running in the same context, this will work regardless of the runtime environment.
See also:
Update: ah, the functional requirement is now more clear.
Actually I want to get lastModified from the file. Is it possible with InputStream? –
Use getResource()
instead to obtain it as an URL
. Then you can open the connection on it and request for the lastModified
.
URL url = getClass().getResource("/main/webapp/resources/styles/some.css");
long lastModified = url.openConnection().getLastModified();
// ...