Java FileOutputStream Create writeFileToDisk(File file, String targetPath)

Here you can find the source of writeFileToDisk(File file, String targetPath)

Description

write File To Disk

License

Apache License

Declaration

public static void writeFileToDisk(File file, String targetPath) 

Method Source Code

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

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

public class Main {

    public static void writeFileToDisk(File file, String targetPath) {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {//w ww. j  a  v  a2  s  .co m
            fis = new FileInputStream(file);
            fos = new FileOutputStream(targetPath);
            byte[] b = new byte[1];
            while (fis.read(b) != -1) {
                fos.write(b);
            }
            fos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                    fis = null;
                }
                if (fos != null) {
                    fos.close();
                    fos = null;
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}

Related

  1. writeFileFromStream(File tempFile, InputStream in)
  2. writeFileFromString(File outputFileName, String content)
  3. writeFileRaw(String fileName, byte[][] contents)
  4. writeFileToByte(byte[] bytes, File file)
  5. writeFileToDisk(ByteArrayOutputStream is, String savePath)
  6. writeFileToFile(File inFile, File toFile)
  7. writeFileToOutputStream(ZipInputStream zipInputStream, File outputFile)
  8. writeFileUTF8(final File file, final String contents)
  9. writeFileWithParent(File file, String contentStr, String charset)