五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

處理流的封裝代碼

2020-04-05 14:12 作者:小垃圾kiki  | 我要投稿
package cn.jd.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/*
?* 隨機讀取和寫入流RandomAccessFile
?*
?*/
public class RandTest04 {
?? ?public static void main(String[] args) throws IOException {
?? ??? ?//分多少塊?? 首先給一個需要分塊的文件
?? ??? ?File src=new File("src/cn/jd/io/Copy.java");
?? ??? ?//文件的總長度
?? ??? ?long? len=src.length();
//?? ??? ?System.out.println(len);
?? ??? ?//每塊大小
?? ??? ?int? blockSize=1024;
?? ??? ?//分多少塊
?? ??? ?int size=(int)Math.ceil(len*1.0/blockSize);//向上取整的意思就是3.5變成4
//?? ??? ?double a=6.0;
//?? ??? ?int b=4;
//?? ??? ?System.out.println(a/b);
?? ??? ?//思路每一塊從哪里開始到哪里結(jié)束
?? ??? ?int beginPos=0;
?? ??? ?int actualSize=(int)(blockSize>len?len:blockSize);? //如果blockSize大于len,那么就選len的長度
?? ??? ?for(int i=0;i<size;i++) {
?? ??? ??? ?beginPos=i*blockSize;
?? ??? ??? ?if(i==size-1) {//最后一塊
?? ??? ??? ??? ?actualSize=(int)len;
?? ??? ??? ?}else {
?? ??? ??? ??? ?actualSize=blockSize;
?? ??? ??? ??? ?len-=actualSize;//剩余長度
?? ??? ??? ?}
?? ??? ??? ?System.out.println(i+"-->"+beginPos+"-->"+actualSize);
?? ??? ??? ?test2(i,beginPos,actualSize);//里面的參數(shù)一定要和下面的方法對應(yīng),出現(xiàn)問題就debug調(diào)試一下
?? ??? ?}
?? ??? ?
?? ??? ?
?? ??? ?
?? ?}
?? ?
?? ?//分塊思想:有了起始索引,有了實際大小
?? ?//指定第i塊的起始位置和實際長度
?? ?public static void test2(int i,int beginPos,int actualSize) throws IOException {
?? ??? ?RandomAccessFile? raf=new RandomAccessFile(new File("src/cn/jd/io/Copy.java"), "r");
?? ??? ?//加入寫出模式
?? ??? ?RandomAccessFile? raf2=new RandomAccessFile(new File("dest/"+i+"Copy.java"), "rw");
//?? ??? ?//起始位置
//?? ??? ?int beginPos=2;
//?? ??? ?//實際大小
//?? ??? ?int actualSize=1026;//我要讀取1026個字節(jié)
//?? ??? ?//隨機讀取
?? ??? ?raf.seek(beginPos); //從第二個索引開始讀取,記住索引是從0開始的
?? ??? ?//讀取??? 讀取方式和字節(jié)流的讀取方式是一樣的
?? ??? ?byte[]? flush=new byte[1024];
?? ??? ?int len=-1;
?? ??? ?while((len=raf.read(flush))!=-1) {
?? ??? ??? ?
?? ??? ??? ?if(len<=actualSize) {//獲取本次讀取的所有內(nèi)容
//?? ??? ??? ??? ?System.out.println(new String(flush,0,len));
?? ??? ??? ??? ?raf2.write(flush,0,len);
//?? ??? ??? ??? ?actualSize-=len;//還剩余多少字節(jié)需要下次讀取
?? ??? ??? ??? ?break;
?? ??? ??? ?}else {
//?? ??? ??? ??? ?System.out.println(new String(flush,0,actualSize));
?? ??? ??? ??? ?raf2.write(flush,0,actualSize);
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ??? ?raf2.close();
?? ??? ?raf.close();
?? ?}

}

處理流的封裝代碼的評論 (共 條)

分享到微博請遵守國家法律
乌兰县| 宁都县| 萍乡市| 澄江县| 宁陕县| 宝鸡市| 宁化县| 新邵县| 恩平市| 清水河县| 神池县| 宝应县| 乌鲁木齐县| 方正县| 依安县| 友谊县| 乌兰浩特市| 内江市| 潍坊市| 曲阜市| 泰安市| 丹阳市| 开原市| 忻城县| 盐津县| 林西县| 开封县| 淮阳县| 禄丰县| 六盘水市| 江源县| 临夏县| 金平| 西林县| 清河县| 盘山县| 大关县| 平和县| 榆社县| 临洮县| 浮山县|