第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

代碼運行出來 文件里是亂碼而且 Arrays.toString()全是0

package RandomAccessFile;


import java.io.File;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.RandomAccessFile;

import java.util.Arrays;


public class Randomaccessfile {

? ? ? ? public static void createfile(String filename){

? ? ? ? File file=new File(filename);

? ? ? ? if(!file.exists()){

? ? ? ? file.mkdir();

? ? ? ?

? ? ? ? }else{

? ? ? ? System.out.println("文件已存在");

? ? ? ? }

? ? ? ? }

?

? ? ??

? ? ? ?

? ? ? ??

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

? ? ? ? ? Randomaccessfile.createfile("demo\\r.dat");

? ? ? ? ? RandomAccessFile r=new RandomAccessFile("r.dat","rw");

? ? ? ? System.out.println(r.getFilePointer());

? ? ? ? ? for(int i=1;i<6;i++){

? ? ? ? ?r.writeDouble(i*1.422);//一個double類型占8個字節(jié)

? ? ? ? ? }

? ? ? ? ? System.out.println(r.getFilePointer());

? ? ? ? ? //把指針指到第四個數(shù)據(jù)后面

? ? ? ? ? r.seek(32);//r.seek(4*8);

? ? ? ? ? r.writeDouble(7*1.2212);//替換第五個數(shù)據(jù)

? ? ? ? ? System.out.println(r.getFilePointer());

? ? ? ??

? ? ? ? ? ? ?r.close();

? ? ? ? ? ? ?

? ? ? ? ? ? ?RandomAccessFile ra=new RandomAccessFile("r.dat","r");

? ? ? ? ? ? ?for(int i=1;i<6;i++){

? ? ? ? ? ? System.out.println("Value "+i+":"+ra.readDouble());;//一個double類型占8個字節(jié)

? ? ? ? ? ? ?}

? ? ? ? ? ? ?byte[] bytes=new byte[(int)ra.length()];

? ? ? ? ? ? ? ? ? ? ? ?ra.read(bytes); ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? System.out.print(Arrays.toString(bytes));

? ? ? ? ? ? ? ? ? ? ?

}

? ? ? ?

}


正在回答

2 回答

那怎么會是亂碼呢?

0 回復(fù) 有任何疑惑可以回復(fù)我~

你的指針位置沒有移動

?RandomAccessFile ra=new RandomAccessFile("r.dat","r");

? ? ? ? ? ? ?for(int i=1;i<6;i++){

? ? ? ? ? ? System.out.println("Value "+i+":"+ra.readDouble());;//一個double類型占8個字節(jié)

? ? ? ? ? ? ?}

? ? ? ? ? ? ?byte[] bytes=new byte[(int)ra.length()];

遍歷文件之后指針在ra.length-1位置,要用ra.seek(0)初始化,才能重新讀取下面的內(nèi)容

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

代碼運行出來 文件里是亂碼而且 Arrays.toString()全是0

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號