Here you can find the source of saveFile(File f, String fileName, File desDir)
Parameter | Description |
---|---|
f | f |
fileName | fileName |
desDir | desDir |
Parameter | Description |
---|---|
IOException | IOException |
public static void saveFile(File f, String fileName, File desDir) throws IOException
//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(); } }