分割设置好分割数量,根据源文件大小来把数据散到子文件中代码如下;

package word;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream; public class Bb { public static void main(String[] args) throws FileNotFoundException {
// TODO 自动生成的方法存根 String path1="C:";
String name="\\JAVA";
String end=".txt";
String path2; long l;
long n=2;//设置分割数目
File file = new File(path1+name+end);
File file2;
l=file.length();
InputStream in = null;
PrintStream out = null;
try { in = new FileInputStream(file);
int tempbyte;
int i=0;
for(i=1;i<=n;i++) {
path2=path1+name+i+end;
file2=new File(path2);
if(file2.exists()) {}
else {
file2.createNewFile();
}
out=new PrintStream(file2);
while ((tempbyte = in.read()) != -1) { out.print((char)tempbyte);
System.out.write(tempbyte);
if(file2.length()>l/n)break;//子文件到达指定大小就创建下一个文件;
} }
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
return; }
}}

合并就是上面的反过程,即把各个小文件输入到大文件中:

package word;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream; public class Bb { public static void main(String[] args) throws FileNotFoundException {
// TODO 自动生成的方法存根 String path1="C:";
String name="\\JAVA";
String end=".txt";
String path2; long n=2;
File file = new File(path1+name+end);
File file2;
l=file.length();
InputStream in = null;
PrintStream out = null;
if(file.exists()) {}
else {
file.createNewFile();
}
out=new PrintStream(file);
try { int tempbyte;
int i=0;
for(i=1;i<=n;i++) {
path2=path1+name+i+end;
file2=new File(path2);
in = new FileInputStream(file2); while ((tempbyte = in.read()) != -1) { out.print((char)tempbyte); } }
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
return; }
}}

最新文章

  1. 转:电子取证中AVI文件的文件雕复
  2. LCM兼容
  3. PL/SQL在win7X 64下安装
  4. jQuery 的 json 格式的处理问题
  5. WAJUEJI which home strong!
  6. phpstorm + xdebug 配置
  7. [Mugeda HTML5技术教程之10]发布内容
  8. Sys.WebForms.PageRequestManagerParserErrorException:无法分析从服务器收到的消息
  9. Struts2 学习笔记 10 Result部分 part1
  10. 在什么情况下使用exist和in
  11. JS解决通过按钮切换图片的问题
  12. Spring之旅第四篇-注解配置详解
  13. 关于macOS 管理员(Admin)权限问题。
  14. 花了几天学习了vue跟做的仿制app
  15. HTTP Status 500 - Error instantiating servlet class cn.it.bd.S011
  16. P1100 高低位交换
  17. zabbix-proxy使用配置
  18. IT这条路,适合什么人走。
  19. ubuntu1604使用之旅——软件源更新(vim安装)
  20. springBoot 学习(总)

热门文章

  1. MySQL学习笔记——基础与进阶篇
  2. Asp.Net Core IdentityServer4 管理面板集成
  3. 分布式SnowFlakeID(雪花ID)原理和改进优化
  4. 【算法】混合流体模拟demo
  5. 基于MySQL+MHA+Haproxy部署高可用负载均衡集群
  6. MongoDB入门(介绍、安装)
  7. rabbit MQ 消息队列
  8. Linux 软件安装卸载 (源码、rpm)
  9. docker安装db2数据库
  10. width、height为auto或者100%的区别