Create a temp file to store the result of a download. - Android File Input Output

Android examples for File Input Output:Temp File

Description

Create a temp file to store the result of a download.

Demo Code


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

import java.io.IOException;

import android.content.Context;

import android.util.Base64;

public class Main {
    /**/*from   ww w  . ja  v  a2  s .c  o m*/
     * Create a temp file to store the result of a download.
     * 
     * @param context
     * @param url
     * @return
     * @throws java.io.IOException
     */
    static private File getTemporaryFile(final Context context,
            final String url) throws IOException {

        // This is what you'd normally call to get a unique temporary
        // file, but for testing purposes we always name the file the
        // same to avoid filling up student phones with numerous
        // files!
        // return context.getFileStreamPath(Base64.encodeToString(url.getBytes(),
        //                                  Base64.NO_WRAP)
        //                                  + System.currentTimeMillis());

        return context.getFileStreamPath(Base64.encodeToString(
                url.getBytes(), Base64.NO_WRAP));
    }
}

Related Tutorials