Skip to content

Instantly share code, notes, and snippets.

@froop
Created January 12, 2012 08:33
Show Gist options
  • Save froop/1599424 to your computer and use it in GitHub Desktop.
Save froop/1599424 to your computer and use it in GitHub Desktop.
[Java] OSのTEMPに一時ディレクトリ作成
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