자바에서 임시폴더 만드는 법

조회수 3310회

자바 응용프로그램 내에서 임시디렉토리를 만드는 표준이나 괜찮은 방법이 있나요?

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    JDK7에서 File.createTempDirectory클래스로 임시 디렉토리를 만들수있습니다.

    그리고 JDK7이 나오기 전에는

    public static File createTempDirectory()
        throws IOException
    {
        final File temp;
    
        temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
    
        if(!(temp.delete()))
        {
            throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
        }
    
        if(!(temp.mkdir()))
        {
            throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
        }
    
        return (temp);
    }
    

    이런식으로 했습니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)