Java FileOutputStream Write saveFile(File f, String fileName, File desDir)

Here you can find the source of saveFile(File f, String fileName, File desDir)

Description

saveFile

License

Open Source License

Parameter

Parameter Description
f f
fileName fileName
desDir desDir

Exception

Parameter Description
IOException IOException

Declaration

public static void saveFile(File f, String fileName, File desDir) throws IOException 

Method Source Code

//package com.java2s;
/*/*from www .  j ava 2  s .co  m*/
 * Copyright (C) 2010 Viettel Telecom. All rights reserved.
 * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

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

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

import java.io.OutputStream;

public class Main {
    /** .*/
    private static final int BUFFER_SIZE = 1024 * 8;

    /**
     * saveFile
     * @param f f
     * @param fileName fileName
     * @param desDir desDir
     * @throws IOException IOException
     */
    public static void saveFile(File f, String fileName, File desDir) throws IOException {
        InputStream stream = new FileInputStream(f);
        OutputStream out = new FileOutputStream(desDir.getAbsolutePath() + File.separator + fileName);
        int bytesRead = 0;
        byte[] buffer = new byte[BUFFER_SIZE];
        while ((bytesRead = stream.read(buffer, 0, BUFFER_SIZE)) != -1) {
            out.write(buffer, 0, bytesRead);
        }
        stream.close();
        out.close();
    }
}

Related

  1. saveDownloadedFile(InputStream is, String destination)
  2. saveEntry(String destPath, ZipEntry target, ZipFile zf)
  3. saveFile(byte[] fileData, String outputDir, String fileName)
  4. saveFile(File f, InputStream stream)
  5. saveFile(File f, String fileName, File desDir)
  6. saveFile(File file, byte[] contenido)
  7. saveFile(File file, InputStream is)
  8. saveFile(File file, String fileName, String filesDirectory)
  9. saveFile(File file, String savePath)