Skip to content

Instantly share code, notes, and snippets.

@sergeykomlach
Created February 8, 2019 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergeykomlach/39c9d843633f3c580ccba62c5618009c to your computer and use it in GitHub Desktop.
Save sergeykomlach/39c9d843633f3c580ccba62c5618009c to your computer and use it in GitHub Desktop.
File dir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS);
if (!dir.exists() && !dir.mkdirs()) {
dir = Environment.getExternalStorageDirectory();
if (!dir.exists() && !dir.mkdirs()) {
throw new IOException(dir.getName() + " permissions denied");
}
}
String name = "file_";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
name = name.concat(sdf.format(Calendar.getInstance().getTime())).concat(".bin");
File dst = new File(dir, name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment