この用途には、あまり便利ではなかったw
java.io.Fileを使うほうがよさそう。
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class FileSplit { private static final String FROM = "C:\\Users\\naoki\\分割対象ファイル"; private static final String TO = "D:\\保存先ディレクトリ"; private static final long LIMIT = 2L * 1024 * 1024 * 1024;//分割サイズ private static final int BUFFER = 65536;//バッファサイズ private static final int STEP = 1024 * 1024 * 100;//経過表示ステップ public static void main(String[] args) throws IOException{ Path from = Paths.get(FROM); long filesize = Files.size(from); long total = 0;//書き込み済みファイルサイズ try(InputStream is = Files.newInputStream(from)){ int index = 1; String filename = from.getName(from.getNameCount() - 1).toString(); byte[] buffer = new byte[BUFFER]; PROC: while(true){ //書き込み先 Path split = Paths.get(TO, filename + "." + index); System.out.printf("writing:%s%n", split); ++index; try(OutputStream os = Files.newOutputStream(split)){ long indicate = 0;//経過表示ファイルサイズ for(long size = 0; size < LIMIT;){ if(size >= indicate){ System.out.printf("%d/%d%n", size, filesize); indicate += STEP; } int readsize = (int) Math.min(BUFFER, LIMIT - size); int s = is.read(buffer, 0, readsize); if(s < 0) break PROC; os.write(buffer, 0, s); size += s; total += s; if(total >= filesize) break PROC; } } } } } }