Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Servlet writing a file inside WEB-INF  RSS feed

 
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want a servlet to write a file inside WEB-INF folder
I tried these things

File file =new File("feedback.txt");

or

File file =new File("/feedback.txt");

or

File file =new File("WEB-INF/feedback.txt");

 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Web apps do not have a default directory - you need to use absolute paths. ServletContext.getRealPath helps with that.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your reply helped me , now i am able to create file using real path.
But still its not writing data to that file , but it have created the file there.
 
Ulf Dittmer
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're closing all Streams and Writers, right?
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its writing now , I was giving wrong path .
Working fine .

Thank you Ulf
 
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I highly recommend against adding files into the context of the web app: what happens to these files when you next redeploy?
 
Ulf Dittmer
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The files might be just fine - deploying into the exploded war file structure (rather than having the servlet container unpack a war file) is not uncommon. But I agree with the sentiment - files should generally be stored outside of the app directory.
 
Greenhorn
Posts: 22
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also not able to write content to file in web-inf, please help


 
Saloon Keeper
Posts: 5038
134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "not able to" mean? What happens if you run this code? Is there code to flush and close the FileWriter?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!