Solved

Have a problem when create folder

Posted on 2010-08-29
3
222 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 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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
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…

705 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