Solved

How to create a file inside the web-app

Posted on 2003-11-27
6
222 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
  • 5
6 Comments
 
LVL 92

Expert Comment

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

Expert Comment

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

Expert Comment

by:objects
Comment Utility
sorry that shopuld have been:

File filesdir = context.getRealPath("/files");
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>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
Comment Utility
Actually it is:

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

Expert Comment

by:objects
Comment Utility
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
noX challenge 17 75
Running Jira on Raspberry PI 2? 3 117
Strange loading of website behaviour 3 22
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now