Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * 
 * For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the
 * file, "LICENSE.txt," in this distribution.
 * 
 */

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**
     * Extract a resource into a real file
     * 
     * @param in typically given as getResources().openRawResource(R.raw.something)
     * @param name of the resulting file
     * @param directory target directory
     * @return the resulting file
     * @throws IOException
     */
    public static File extractResource(InputStream in, String filename, File directory) throws IOException {
        int n = in.available();
        byte[] buffer = new byte[n];
        in.read(buffer);
        in.close();
        File file = new File(directory, filename);
        FileOutputStream out = new FileOutputStream(file);
        out.write(buffer);
        out.close();
        return file;
    }
}