• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file access problem

 
Yewint Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
I have been implementing a small code which will access some files within the same context. Currently I have a servlet and implemented as follow to access the files.



I got the file not found exception when the app is run. "variations.uni" file is placed in the root of the app .My dir structure is as follow



please help me solve this problem.



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The context path is a concept for URLs, not file paths.

What are you really trying to do? Where do you want the file to be?
 
Yewint Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The context path is a concept for URLs, not file paths.



Oh yes,I just want to read/write the file in the root of app .

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Investigate ServletContext.getRealPath()
 
Yewint Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks so much , bear. I havent accessed files with Stream in web environment before and didnt know that method exists. You help me a lot.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, just be aware that writing into your web app is not generally considered a great thing to do. It can make redeployment and updates a pain.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic