• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create File object for servlet and so where to place the folder

 
Huzefa Zohaib
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a File object in the class which will be used by servlet There is a directory "xyz" which I want to pass in the constructor of File object. So where I should place the directory.
Class file is in
C:\Back\tomcat3\webapps\ROOT\WEB-INF\classes\abc\def\LoadDir.class
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the directory is the directory.

Wherever you place it.. that's what xyz should say.
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xyz is just another directory that the file in question is located in? I am not sure how this is relevant. Just make the call to the file in the constructor.
If the xyz directory is relative to the context of your application:
File file = new File("xyz/MyFile.txt");
Otherwise:
File file = new File("C:/mydocs/xyz/MyFile.txt");
No worries....
 
Huzefa Zohaib
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
But I think you didn't understand the objective of my question.
I want to create the file object in the class running in the tomcat server environment so will I create the file object.
Like this

but if I restrict the threads only to their assigned folders(as happend in mycgiserver.com or any other .com server) than I can't create the file object by giving the absolute path.
Then I need to create the object something like this

but in this case where should be the in folder xyz so that file object could be created without any exception.but in this case where should be the in folder xyz so that file object could be created without any exception.
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would imagine int the root directory is where you'd start. Try this:
new File("WEB-INF/classes/abc/def/xyz")
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!