Solved

Have a problem when create folder

Posted on 2010-08-29
3
215 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
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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 …
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

746 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