Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mkdirs()

Posted on 2008-10-16
8
Medium Priority
?
309 Views
Last Modified: 2013-11-24
Hi

I need to create a directory under webapps/test/
which test is the application folder
http://localhost:8080/test/

I want to create http://localhost:8080/test/upload/abc/

The code does not create any folder.
private String uploadPath = "/upload/abc/", filepath;
filepath = request.getContextPath() + uploadPath;
File tempPathFile = new File(filepath);
if (!tempPathFile.exists()) {
tempPathFile.mkdirs();
}

Open in new window

0
Comment
Question by:techques
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 20

Expert Comment

by:Venabili
ID: 22729040
Try to use
private String uploadPath = "upload/abc"; //no / at the end or the beginning
File tempPathFile = new File(request.getContextPath(), uploadPath); //leave Java to do the concatenations
this will at least make sure the folders are created ok.

Also - had you printed request.getContextPath() to make sure it is where it is supposed to be?

Other from this:
- See the log files for permission issues (you might not be able to create folders especially on a Unix if you do not have the permissions. (Put a try catch block - the method should throw an exception if this is the issue)

By the way...
private String uploadPath = "/upload/abc/", filepath;
is a bad practice and can lead to some strange issues if you need to change something... use
private String uploadPath = "/upload/abc/";
private String filepath;
0
 

Author Comment

by:techques
ID: 22729074
request.getContextPath()

/upload/abc/

if i use getServletContext().getRealPath(uploadPath);

C:\\Tomcat 6.0\\webapps\\test\\upload\\abc
0
 

Author Comment

by:techques
ID: 22729078
still cannot create directory under tomcat webapps

i think it cannot do that, may have to use absolute local path
0
Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

 
LVL 20

Expert Comment

by:Venabili
ID: 22729322
That's it I think. You need to pass the FULL path (that's why I asked for the request.getContextPath() -- if it is relative, you should get the real path.
In any way - I am always getting to real paths for any directory creations.
0
 

Author Comment

by:techques
ID: 22731158
I think servlet cannot do it as I finally need to use the local full path
C:\\Tomcat 6.0\\webapps\\test\\upload\\abc

Neither request.getContextPath nor getServletContext().getRealPath did not work
0
 
LVL 28

Expert Comment

by:rrz
ID: 22732167
0
 

Author Comment

by:techques
ID: 22737710
give up, i think servlet does not support it
0
 
LVL 28

Accepted Solution

by:
rrz earned 150 total points
ID: 22737761
Don't give up. Post your complete code. We will debug it
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

670 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