Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 42975
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: 42975
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
 
Author and ninkuma
Marshal
Posts: 66610
161
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: 42975
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: 4413
108
  • 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!