Here you can find the source of copyImgFile(String sourcePath, String fileId)
Parameter | Description |
---|---|
sourcePath | a parameter |
fileId | a parameter |
public static void copyImgFile(String sourcePath, String fileId)
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import android.os.Environment; public class Main { /**//from www . java 2s.co m * * @param sourcePath * @param fileId */ public static void copyImgFile(String sourcePath, String fileId) { String newPath = getImageDir() + fileId; try { int bytesum = 0; int byteread = 0; File oldfile = new File(sourcePath); if (oldfile.exists()) { InputStream inStream = new FileInputStream(sourcePath); FileOutputStream fs = new FileOutputStream(newPath); byte[] buffer = new byte[1444]; int length; while ((byteread = inStream.read(buffer)) != -1) { bytesum += byteread; System.out.println(bytesum); fs.write(buffer, 0, byteread); } inStream.close(); } } catch (Exception e) { e.printStackTrace(); } } public static String getImageDir() { String fileDir = Environment.getExternalStorageDirectory() + "/fantasy/"; File dirFile = new File(fileDir); if (!dirFile.exists()) { dirFile.mkdirs(); } return fileDir; } }