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

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

隨機(jī)流分塊代碼

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

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

/*
?* 隨機(jī)讀取和寫(xiě)入流RandomAccessFile
?*
?*/
public class RandTest01 {
?? ?public static void main(String[] args) throws IOException {
?? ??? ?//分多少塊?? 首先給一個(gè)需要分塊的文件
?? ??? ?File src=new File("src/cn/jd/io/Copy.java");
?? ??? ?//文件的總長(zhǎng)度
?? ??? ?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);
?? ??? ?//思路每一塊從哪里開(kāi)始到哪里結(jié)束
?? ??? ?int beginPos=0;
?? ??? ?int actualSize=(int)(blockSize>len?len:blockSize);? //如果blockSize大于len,那么就去len的長(zhǎng)度
?? ??? ?for(int i=0;i<size;i++) {
?? ??? ??? ?beginPos=i*blockSize;
?? ??? ??? ?if(i==size-1) {//最后一塊
?? ??? ??? ??? ?actualSize=(int)len;
?? ??? ??? ?}else {
?? ??? ??? ??? ?actualSize=blockSize;
?? ??? ??? ??? ?len-=actualSize;//剩余長(zhǎng)度
?? ??? ??? ?}
?? ??? ??? ?System.out.println(i+"-->"+beginPos+"-->"+actualSize);
?? ??? ??? ?test2(i,beginPos,actualSize);
?? ??? ?}
?? ??? ?
?? ??? ?
?? ??? ?
?? ?}
?? ?
?? ?//分塊思想:有了起始索引,有了實(shí)際大小
?? ?//指定第i塊的起始位置和實(shí)際長(zhǎng)度
?? ?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");
//?? ??? ?//起始位置
//?? ??? ?int beginPos=2;
//?? ??? ?//實(shí)際大小
//?? ??? ?int actualSize=1026;//我要讀取1026個(gè)字節(jié)
//?? ??? ?//隨機(jī)讀取
//?? ??? ?raf.seek(beginPos); //從第二個(gè)索引開(kāi)始讀取,記住索引是從0開(kāi)始的
?? ??? ?//讀取??? 讀取方式和字節(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));
?? ??? ??? ??? ?actualSize-=len;//還剩余多少字節(jié)需要下次讀取
?? ??? ??? ?}else {
?? ??? ??? ??? ?System.out.println(new String(flush,0,actualSize));
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?
?? ??? ?
?? ??? ?raf.close();
?? ?}

}

隨機(jī)流分塊代碼的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
鹤壁市| 滨州市| 东城区| 宜州市| 怀来县| 蒙城县| 河北区| 绍兴市| 古交市| 南召县| 大足县| 建平县| 新昌县| 河东区| 商都县| 彰武县| 乌拉特中旗| 白水县| 莫力| 保亭| 青铜峡市| 融水| 庆城县| 蓝田县| 黎平县| 清远市| 虞城县| 云和县| 西畴县| 贺州市| 蓬莱市| 顺义区| 文山县| 洪江市| 泰顺县| 大埔县| 杭州市| 大渡口区| 商河县| 越西县| 鹰潭市|