Java tutorial
//package com.java2s; /* * Copyright (c) 2013, David Brodsky. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import android.content.Context; import android.util.Log; import java.io.File; import java.io.IOException; public class Main { static final String TAG = "FileUtils"; /** * Returns a TempFile with given root, filename, and extension. * The resulting TempFile is safe for use with Android's MediaRecorder * @param c * @param root * @param filename * @param extension * @return */ public static File createTempFile(Context c, File root, String filename, String extension) { File output = null; try { if (filename != null) { if (!extension.contains(".")) extension = "." + extension; output = new File(root, filename + extension); output.createNewFile(); //output = File.createTempFile(filename, extension, root); Log.i(TAG, "Created temp file: " + output.getAbsolutePath()); } return output; } catch (IOException e) { e.printStackTrace(); return null; } } }