Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

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

public class Main {

    public static void copyStream2File(InputStream is, File desc) throws IOException {
        OutputStream os = null;
        try {
            os = new FileOutputStream(desc);
            copyStream(is, os);
        } finally {
            if (os != null)
                os.close();
        }
    }

    public static void copyStream(InputStream is, OutputStream os) throws IOException {
        byte buffer[] = new byte[1024];
        int len = -1;
        while ((len = is.read(buffer, 0, 1024)) != -1) {
            os.write(buffer, 0, len);
        }
    }
}