Solved

How to create a file inside the web-app

Posted on 2003-11-27
6
227 Views
Last Modified: 2010-03-31
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 ??
0
Comment
Question by:rahulkothari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9834070
You need access to the ServletContext for your webapp, and use it's getRealPath() method.
0
 
LVL 92

Expert Comment

by:objects
ID: 9834083
File filesdir = context.RealPath("/files");
0
 
LVL 92

Expert Comment

by:objects
ID: 9834085
sorry that shopuld have been:

File filesdir = context.getRealPath("/files");
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 9834113
>>File filesdir = context.getRealPath("/files");

are you sure it's not

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

?
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 9834131
Actually it is:

File filesdir = new File(context.getRealPath("/files"));
0
 
LVL 92

Expert Comment

by:objects
ID: 9890016
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question