Created
January 12, 2012 08:33
-
-
Save froop/1599424 to your computer and use it in GitHub Desktop.
[Java] OSのTEMPに一時ディレクトリ作成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TempDir { | |
private final File dir; | |
public TempDir(String prefix) { | |
String name = prefix + "_" + UUID.randomUUID().toString(); | |
dir = new File(System.getProperty("java.io.tmpdir"), name); | |
boolean success = dir.mkdir(); | |
if (!success) { | |
throw new RuntimeException(dir.getPath()); | |
} | |
dir.deleteOnExit(); | |
} | |
public String getPath() { | |
return dir.getPath(); | |
} | |
public void delete() { | |
try { | |
FileUtils.deleteDirectory(dir); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment