2012-01-25 2 views
0

폴더가 만들어지지 않았다는 사실에 고민하고 있습니다.새 디렉토리 만들기

private static File createNewTempDir() { 
File baseDir = new File(System.getProperty("java.io.tmpdir")); 
String baseNamePrefix = System.currentTimeMillis() + "_" + Math.random() + "-"; 
LOG.info(System.getProperty("java.io.tmpdir")); 
File tempDir = new File(baseDir, baseNamePrefix + "0"); 
LOG.info(tempDir.getAbsolutePath()); 

tempDir.mkdirs(); 

if (tempDir.exists()) { 
    LOG.info("I would be happy!"); 
} 
else { 
    LOG.info("No folder there"); 
} 
return tempDir; 
} 

거기에 문제가 있습니까?

이 폴더가 실제로 만들어
if (tempDir.exists()) { 
    LOG.info("I would be happy!"); 
} 
else { 
    LOG.info("No folder there"); 
} 

, 당신이 경로를 얻어서 있음을 확인하실 수 있습니다 : 나는

+0

폴더가 없습니까? 당신은 그것이 존재할 때만 거기에 기록하지 않습니다. –

+0

문제는 'if (! tempDir.exists())'의 부정이라고 생각됩니다. 그게 "나는 행복 할거야!"라고 인쇄 할 것입니다. 경로가 존재하지 않으면 "No folder there"라고 표시됩니다. –

+0

개미와 어떤 관련이 있습니까? 나는 그것의 사용법을 볼 수 없다. 어쩌면 태그를 제거해야합니다. – joergl

답변

2

귀하의 코드는 괜찮지 만, 조건부가 잘못 ... 어떤 폴더가 있는지 로그를 얻을 수 있습니다 Explorer에서 여는 중입니다.

편집 : 적어도 Windows에서 작동합니다. 나는 조금 그것을 청소 :

public static void main() { 
     File baseDir = new File(System.getProperty("java.io.tmpdir")); 
     File tempDir = new File(baseDir, "test0"); 
     System.err.println(tempDir.getAbsolutePath()); 

     tempDir.mkdir(); 

     System.err.println("is it a dir? " + tempDir.isDirectory()); 
     System.err.println("does it exist? " + tempDir.exists()); 
    } 

출력 :

C : \ 사용자 \ marsch1 \의 AppData \ 로컬 \ 임시 \의 test0 이 말 일세입니까? 사실 존재합니까? true

+0

미안 마르셀로, 내가 잘못 입력 했어. –

+0

Thx Marcelo. 나는 왜이 문제가 발생했는지 모른다. 당신의 코드를 따라 가면 폴더가 만들어 졌는지 확인할 수 있습니다. 하지만 제 코드를 따르면 작동하지 않습니다. 어쨌든, 도움을 청합니다. 이후 문제를 확인 하겠지만 더 많은 해결책이 필요합니다 ... 어쨌든 도움을 주신 덕분에 –

+0

Rude-Student, 방금 file.mkdirS() 대신에'file.mkdir()'을 사용한다는 것을 깨달았습니다. 아마 그게 네 문제 야? – Marcelo

관련 문제