This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have a problem: I have a file under /WEB-INF/data/myfile.xml
But when I try to write in this file, a FileNotFound is throw by:
final FileOutputStream fos = new FileOutputStream(
new File(Thread.currentThread().getContextClassLoader()
.getResource("/").toString().replace("classes/", "data/"+instanceFileName));
I think the file isn't found because is protected no ? (If I copy/paste the file url returned
in my navigator, the file can be available)
Can I specify file can be written under my web app, with a parameter like (in web.xml):
You can get the file path to the context from the ServletContext, provided it is not packaged as a WAR (not a good idea to make this assumption without checking) but you're right that the ClassLoader will not let you browse outside the entries on the classpath.
Adrien Ruffie
Ranch Hand
Joined: Jan 14, 2009
Posts: 71
posted
0
Yes I can found the file path to the context but if I try file.exist() the function return false to me ... The URI is correct but it seems, that it seems invisible.
I can also retrieve the path by ClassLoader but same problem occurred ...
Do you to a method like ServletContext.getResourceAsStream, but returning an outputstream of my file instead inputstream ?