Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.os.Environment;

import java.io.File;
import java.io.FileOutputStream;

import java.io.InputStream;

public class Main {
    public static void copyToSD(InputStream in, String fileName) {
        String path = Environment.getExternalStorageDirectory() + File.separator + fileName;
        File file = new File(path);
        try {
            FileOutputStream fos = new FileOutputStream(file);
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = in.read(buffer)) != -1) {
                fos.write(buffer, 0, len);
            }
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}