How to create a file inside the web-app

I have a java class that resides inside com.pappu.kumar package , inside my web-app (name=test). So the structure is something like :

test
  |
  |--jsp
  |
  |--files
  |
  |--WEB-INF
        |
        |--lib
        |--classes
              |--com
                   |--pappu
                        |--kummar
                              |-CreateFile.class  

Now in CreateFile.class , i try to create a file . What path should i give so that i can create the file in the "files" directory , i would like to use a way that works both on unix and windows. And if its not possible to create under "files" , whats the easiest way to create the file in some folder ??
rahulkothariAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
Actually it is:

File filesdir = new File(context.getRealPath("/files"));
0
 
objectsCommented:
You need access to the ServletContext for your webapp, and use it's getRealPath() method.
0
 
objectsCommented:
File filesdir = context.RealPath("/files");
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
objectsCommented:
sorry that shopuld have been:

File filesdir = context.getRealPath("/files");
0
 
CEHJCommented:
>>File filesdir = context.getRealPath("/files");

are you sure it's not

File filesdir = context.getRealPath("../files");

?
0
 
objectsCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.