Android File Copy copyImgFile(String sourcePath, String fileId)

Here you can find the source of copyImgFile(String sourcePath, String fileId)

Description

copy Img File

Parameter

Parameter Description
sourcePath a parameter
fileId a parameter

Declaration

public static void copyImgFile(String sourcePath, String fileId) 

Method Source Code

//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;
    }
}

Related

  1. copyFile(String strSrc, String strDest)
  2. copyFileByCommand(String src, String dst, boolean isMove)
  3. copyFileLazy(String source, String destination)
  4. copyFileToFile(File file, File outFile)
  5. copyFiles(File src, File dst)
  6. copyResource(Class cls, String strResSource, String strFile)
  7. copyStringToFile(String content, String FilePath)
  8. copyfile(File source, File destination)
  9. dumbfilecopy(File source, File dest)