日期:2014-05-20 浏览次数:20754 次
package com.ray.tests.cutfile; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class CutFile { public static void main(String[] args) throws IOException { cutFile("src/com/ray/tests/cutfile/file.txt", 2000); } public static void cutFile(String fileName, int size) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); int len; int count = 1; char[] cbuf = new char[size]; while ((len = reader.read(cbuf, 0, size)) != -1) { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName + "_" + count))); writer.write(cbuf, 0, len); writer.flush(); writer.close(); count++; } } }