Java File Object Create toFile(InputStream in, File file)

Here you can find the source of toFile(InputStream in, File file)

Description

to File

License

Apache License

Declaration

static public int toFile(InputStream in, File file) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    static public int toFile(InputStream in, File file) throws IOException {
        try (FileOutputStream out = new FileOutputStream(file)) {
            return copyStream(in, out);
        }/*from ww w . j  a va 2 s. c  o m*/
    }

    static public int copyStream(InputStream in, OutputStream out) throws IOException {
        int length = 0;

        byte[] buffer = new byte[1024];
        for (int read = in.read(buffer); read != -1; read = in.read(buffer)) {
            out.write(buffer, 0, read);
            length += read;
        }
        out.flush();
        out.close();

        return length;
    }
}

Related

  1. toFile(File currentDirectory, String file)
  2. toFile(File dir, String[] path)
  3. toFile(File dstPath, String fullClassName)
  4. toFile(File file, byte[] data)
  5. toFile(IFile file)
  6. toFile(InputStream inputStream)
  7. toFile(JavaFileObject javaFileObject)
  8. toFile(List filenames)
  9. toFile(Map res, String output)