Java tutorial
//package com.java2s; /* * Copyright (c) 2015 The CCP project authors. All Rights Reserved. * * Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license * that can be found in the LICENSE file in the root of the web site. * * http://www.yuntongxun.com * * An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ import java.io.File; import java.util.Date; import android.content.Context; import android.os.Environment; public class Main { public static File createFile(Context context) { File file; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String timeStamp = String.valueOf(new Date().getTime()); file = new File(Environment.getExternalStorageDirectory() + File.separator + timeStamp + ".jpg"); } else { File cacheDir = context.getCacheDir(); String timeStamp = String.valueOf(new Date().getTime()); file = new File(cacheDir, timeStamp + ".jpg"); } return file; } }