Android InputStream Save saveToLocal(InputStream in, String filePath)

Here you can find the source of saveToLocal(InputStream in, String filePath)

Description

save To Local

Declaration

public static void saveToLocal(InputStream in, String filePath) 

Method Source Code

//package com.java2s;

import java.io.DataOutputStream;
import java.io.File;

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

public class Main {

    public static void saveToLocal(InputStream in, String filePath) {
        try {/*from   ww  w .  j  a v  a 2s  .  c  o  m*/
            File file = new File(filePath);
            if (!file.exists() && !file.isDirectory()) {
                file.createNewFile();
            }
            DataOutputStream out = new DataOutputStream(
                    new FileOutputStream(new File(file.getAbsolutePath())));
            byte[] dataByte = new byte[in.available()];
            in.read(dataByte);
            for (int i = 0; i < dataByte.length; i++)
                out.write(dataByte[i]);
            out.flush();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. dumpToFile(File file, InputStream inputStream)
  2. saveFile(InputStream in, String fileName)
  3. writerFromInputStream(InputStream stream, String path, String fileName)
  4. writeFile(File outputFile, InputStream inputStream)
  5. saveFile(Context context, String fileName, InputStream inputStream)
  6. writeXmlToTempFile(InputStream xmlStream, String filePath, String closingTag)