make Temporary File - Android java.io

Android examples for java.io:Temporary File

Description

make Temporary File

Demo Code

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.sun.istack.internal.Nullable;

import android.content.Context;

public class Main {

  @SuppressWarnings({ "ConstantConditions", "ResultOfMethodCallIgnored" })
  public static File makeTempFile(Context context, @Nullable String saveDir, String extension) {
    if (saveDir == null)
      saveDir = context.getExternalCacheDir().getAbsolutePath();
    final String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    final File dir = new File(saveDir);
    dir.mkdirs();/*from ww  w.j  av a  2 s  .  com*/
    return new File(dir, "VID_" + timeStamp + extension);
  }

}

Related Tutorials