Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.File;

public class Main {
    public static void divideFile() throws IOException {
        String path = "F:/ar/";
        String base = "phoneAttribution";
        String ext = ".db";

        int split = 800 * 1024;
        byte[] buf = new byte[1024];
        int num = 1;

        File inFile = new File(path + base + ext);
        FileInputStream fis = new FileInputStream(inFile);
        while (true) {
            FileOutputStream fos = new FileOutputStream(new File(path + base + num + ext));
            for (int i = 0; i < split / buf.length; i++) {
                int read = fis.read(buf);
                fos.write(buf, 0, buf.length);
                if (read < buf.length) {
                    fis.close();
                    fos.close();
                    return;
                }
            }
            fos.close();
            num++;
        }
    }
}