Solved

Have a problem when create folder

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 38
ForLoop Example 3 48
varialbe initialization 11 32
tomcat not starting 6 45
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

785 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