Question:
how to create a simple text file in a java web application?
kanna
2006-09-12 02:19:09 UTC
how should we create a simple text file in a web application.
i used
File file = new File("reports/one.txt");
to create a text file under the reports folder .This "reports" folder is along with the web-inf folder.
when i executed the servlet which had this code,its creating the file some where out side the application. i want that to create under the "reports" folder. how to achieve this. please help me.
Three answers:
vincentgl
2006-09-15 22:01:38 UTC
I bet it's creating the path/file relative to where the application (e.g. Tomcat) was started from, or from the user directory.



Use the ServletContext's getRealPath() method instead:

http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
anonymous
2016-11-14 13:29:46 UTC
Create Text File Java
Joe_Young
2006-09-12 02:22:32 UTC
kanna You will find your answer with this link



http://www.google.co.uk/search?hl=en&q=+text+file+in+a+java+web+application&btnG=Search&meta=


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...