get Output File - Android java.io

Android examples for java.io:File Path

Description

get Output File

Demo Code


//package com.java2s;
import java.io.File;

import java.io.IOException;

import android.util.Log;

public class Main {
    /***// ww  w  . j a  va  2 s.co  m
     * 
     * getOutputFile
     * @return output file in jpeg format
     */
    public static File getOutputFile(String directory) {
        File dir = new File(directory);
        if (!dir.exists()) {
            boolean flag = dir.mkdir();
        }

        File f = new File(dir.getAbsolutePath(), "IMG"
                + System.currentTimeMillis() + ".jpeg");
        try {
            f.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.d("Error in creating file", e.toString());
        }
        return f;
    }
}

Related Tutorials