2014-06-25 2 views
0

내 웹 프로젝트는 Tomcat + jsp입니다. 이 프로젝트에서 폴더를 만들려고 할 때 코드에 예외가없고 항상 폴더가 표시됩니다. 그러나 디렉터리에서 폴더를 찾을 수 없습니다.Web Project에서 폴더를 만드시겠습니까?

private static final String imagFolder="pictures"; 
private static final String Separator=java.io.File.separator; 
String directory = request.getContextPath()+Separator+imagFolder; 
CreateFileUtil.createDir(directory); 

***** CreateFileUtil.createDir ************************ 다음과 같이

내 코드입니다 *************

public static boolean createDir(String destDirName) { 
    File dir = new File(destDirName); 
    if (dir.exists()) {// in this line,there is not exception and return true however, when I check the direcotry ,there folder doesn't exists 
     System.out.println("create directory" + destDirName + "Failure, it already exists"); 
     return false; 
    } 
    if (!destDirName.endsWith(File.separator)) { 
     destDirName = destDirName + File.separator; 
    } 
    //create 
    if (dir.mkdirs()) { 
     System.out.println("create directory" + destDirName + "Success"); 
     return true; 
    } else { 
     System.out.println("create directory" + destDirName + "Failure"); 
     return false; 
    } 
} 
+0

마지막으로 문제가 흠뻑 젖어 있습니다. – user3239558

답변

0

마지막으로 문제가 해결되었습니다.

String directory= request.getServletContext().getRealPath("/")+Separator+imagFolder; 

그럼 성공에

String directory = request.getContextPath()+Separator+imagFolder; 

:

난 그냥 코드를 변경합니다.

관련 문제