Android Utililty Methods File Copy

List of utility methods to do File Copy

Description

The list of methods to do File Copy are organized into topic(s).

Method

voidcopyImgFile(String sourcePath, String fileId)
copy Img File
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);
...
booleancopyResource(Class cls, String strResSource, String strFile)
Copy resource to file
InputStream isSrc = null;
FileOutputStream osDest = null;
try {
    isSrc = cls.getResourceAsStream(strResSource);
    if (isSrc == null)
        throw new IOException("Resource " + strResSource
                + " not found");
    osDest = new FileOutputStream(strFile);
...
voidcopyStringToFile(String content, String FilePath)
Copy String to a File.
FileWriter fstream = new FileWriter(FilePath);
BufferedWriter out = new BufferedWriter(fstream);
out.write(content);
out.close();
voidcopyfile(File source, File destination)
copyfile
FileUtils.copyFile(source, destination);
voiddumbfilecopy(File source, File dest)
Copies a file.
FileOutputStream out = new FileOutputStream(dest);
FileInputStream in = new FileInputStream(source);
byte[] buf = new byte[(int) source.length()];
in.read(buf);
out.write(buf);
in.close();
out.close();
voidfileCopy(File dbFile, File backup)
file Copy
FileChannel inChannel = new FileInputStream(dbFile).getChannel();
FileChannel outChannel = new FileOutputStream(backup).getChannel();
try {
    inChannel.transferTo(0, inChannel.size(), outChannel);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (inChannel != null) {
...
voidfileCopy(File sourcefile, File destinctionFile)
file Copy
FileInputStream stFileInputStream = null;
FileOutputStream stFileOutputStream = null;
try {
    stFileInputStream = new FileInputStream(sourcefile);
    stFileOutputStream = new FileOutputStream(destinctionFile);
    int arraySize = 1024;
    byte buffer[] = new byte[arraySize];
    int bytesRead;
...
voidfileCopy(File sourcefile, String destinctionFile)
file Copy
FileInputStream stFileInputStream = null;
FileOutputStream stFileOutputStream = null;
try {
    makeFile(destinctionFile);
    stFileInputStream = new FileInputStream(sourcefile);
    stFileOutputStream = new FileOutputStream(destinctionFile);
    int arraySize = 1024;
    byte buffer[] = new byte[arraySize];
...
voidfileCopy(String sourcefile, String destinctionFile)
file Copy
fileCopy(new File(sourcefile), destinctionFile);
voidbakFile(String source, String dest)
bak File
File file = new File(source);
boolean state = file.renameTo(new File(dest));
if (!state) {
    fileCopy(source, dest);
    deleteFileOnly(source);