Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
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 android.content.Context;

public class Main {
    public static void copyToMemory(Context context, String srcFilePath, String dictFileName) throws IOException {
        File srcFile = new File(srcFilePath);
        if (!srcFile.exists() || srcFile.isDirectory()) {
            return;
        }
        BufferedInputStream inBufferedInputStream = new BufferedInputStream(new FileInputStream(srcFile));
        FileOutputStream fos = context.openFileOutput(dictFileName, 0);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        byte[] b = new byte[1024 * 4];
        int len;
        while ((len = inBufferedInputStream.read(b)) != -1) {
            bos.write(b, 0, len);
            bos.flush();
        }
        inBufferedInputStream.close();
        bos.close();
    }
}