Android examples for java.io:File Copy
copy file via File objects
import android.annotation.SuppressLint; import android.content.ClipDescription; import android.content.Context; import android.net.Uri; import android.os.StatFs; import android.util.Log; import android.webkit.URLUtil; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; public class Main{ /**/*w w w .ja v a2s .c om*/ * copies file * @param source * @param destination * @throws IOException */ public static void copyOrdinaryFile(File source, File destination) throws IOException { InputStream in = new BufferedInputStream( new FileInputStream(source)); OutputStream out = new BufferedOutputStream(new FileOutputStream( destination)); try { byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.flush(); } finally { in.close(); out.close(); } } }