将InputStream写入本地文件


/**
     * 将InputStream写入本地文件
     * @param destination 写入本地目录
     * @param input    输入流
     * @throws IOException
     */
    private static void writeToLocal(String destination, InputStream input)
            throws IOException {
        int index;
        byte[] bytes = new byte[1024];
        FileOutputStream downloadFile = new FileOutputStream(destination);
        while ((index = input.read(bytes)) != -1) {
            downloadFile.write(bytes, 0, index);
            downloadFile.flush();
        }
        downloadFile.close();
        input.close();
    }

 

 

 

/**
* 将bytes写入本地文件
* @param destination
* @param bytes
* @throws IOException
*/
private static void writeToLocal(String destination, byte[] bytes) throws IOException {
  FileOutputStream downloadFile = new FileOutputStream(destination);
  downloadFile.write(bytes);
  downloadFile.flush();
  downloadFile.close();
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM