Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Have a problem when create folder

Posted on 2010-08-29
3
Medium Priority
?
224 Views
Last Modified: 2013-11-23
Hi experts,
I'm having a problem in creating a folder.  It failed create a folder.  I have tried with two folder:
A) C:/apache-tomcat-6.0.18/webapps/grid50/grid_archive
B) C:/apache-tomcat-6.0.18/webapps/grid50/grid_archive/ram/0

For create (A) folder it's doesn't have a problem.  But when I create (B) folder it's failed. Below is the code.
public String createTempDir2(int module, int mid) throws Exception{
		boolean bGotFolder = true;
		String tempPath = null;
		String tempdir = null;
		
		try{
			
			tempdir = System.getProperty("archive_path");			
			
			if(module == 1)
			{
				tempPath = tempdir+"/erm"+"/"+mid;
			}
			else if(module == 2 )
			{
				tempPath = tempdir+"/ram"+"/"+mid;			 
			}		
			
		    if(log.isDebugEnabled())
		    	log.debug("Default temp file path = " + tempPath);
		    
		    File folderExisting = new File(tempPath);
		    
			if (!folderExisting.isDirectory() || !folderExisting.exists())
			{
				if(!folderExisting.mkdir())
				{
			    	if(!folderExisting.isDirectory())
			    	{	    		
			    		
			    		if(log.isDebugEnabled())
			    			log.debug("Failed to create temp because a file with same name exists. ");
			    		
			    		if(folderExisting.delete())
			    		{
				    		if(!folderExisting.mkdir())
				    		{
								bGotFolder = false;
								
								if(log.isDebugEnabled())
									log.debug("Failed to create temp");
				    		}
				    		else
				    		{
				    			if(log.isDebugEnabled())
									log.debug("Created new dir after deleting file, name = " + folderExisting.getPath());				    			
				    		}
			    		}
			    		else
			    		{
							bGotFolder = false;
							
				    		if(log.isDebugEnabled())
				    			log.debug("Failed to delete the file.");			    			
			    		}
			    	}
			    	else
			    	{
						bGotFolder = false;
						
			    		if(log.isDebugEnabled())
			    			log.debug("Failed to create temp folder.");
			    	}
				}
				else
				{
				    if(log.isDebugEnabled())
				    	log.debug("Created new dir, name = " + folderExisting.getPath());					
				}		
				
			}			
								
		}
		catch(Exception e)
		{
		    log.error("function = createTempDir2(); desc = "+e);		    
		}

		return tempPath;
	}

Open in new window

0
Comment
Question by:sitijaafar
[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
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 33555479
0
 

Author Comment

by:sitijaafar
ID: 33555551
it's work. So, in what condition to know whether to use mkdir or mkdirs?
0
 
LVL 92

Expert Comment

by:objects
ID: 33555570
whether the parent directory exists or not
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

596 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