博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java——IO流(文件分割)_8
阅读量:2292 次
发布时间:2019-05-09

本文共 1149 字,大约阅读时间需要 3 分钟。

package RandTest_11;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import java.io.RandomAccessFile;public class RandTest_3 {
public static void main(String[] args) throws IOException {
File src = new File("a.html"); long len = src.length(); //总长度 int blockSize = 1024; //块大小 int size = (int) Math.ceil((len*1.0/blockSize)); //块个数 System.out.println(size); int beginPos = 0; //起始位置 int actualSize; //实际大小 for(int i = 0 ; i
"+beginPos+"-->"+actualSize); split(beginPos, actualSize); } } public static void split(int beginPos,int actualSize) throws IOException {
RandomAccessFile raf = new RandomAccessFile(new File("a.html"), "r");// System.out.println(raf.length()); raf.seek(beginPos); //设置起始位置 byte[] datas = new byte[1024]; //缓冲容器 int len = -1; while((len=raf.read(datas))!=-1) {
if(actualSize>len) {
//获取本次读取的所有内容 System.out.println(new String(datas,0,len,"UTF-8")); actualSize -=len;// System.out.println("测试"); }else {
System.out.println(new String(datas,0,actualSize,"UTF-8")); break; } } raf.close(); }}

转载地址:http://fisnb.baihongyu.com/

你可能感兴趣的文章
Simple Zend_Layout Example
查看>>
The Zend Framework MVC Architecture
查看>>
Framework框架分析总结
查看>>
Windows7下centOS 硬盘安装双系统
查看>>
GRUB引导程序参数
查看>>
phpMyAdmin简明安装教程
查看>>
独立安装LAMP时需要注意的几点
查看>>
socket
查看>>
判断远程url是否有效的几种方法
查看>>
javascript中编写类似in_array()的原型函数
查看>>
go 数据库操作
查看>>
php读取二进制流
查看>>
Golang热重启
查看>>
热重启golang服务器(graceful restart golang http server)
查看>>
echo框架使用:获取与配置
查看>>
PHP模拟多进程并发将内容写入文件
查看>>
nginx.conf配置说明
查看>>
Eclipse设定和修改文件字符编码格式和换行符
查看>>
git常用操作以及快速入门教程
查看>>
MongoDB 3.0 常见集群的搭建(主从复制,副本集,分片....)
查看>>