簡單的檔案讀寫

2021-08-07 16:43:26 字數 887 閱讀 8479

randomaccessfile

randomaccessfile raf = new randomaccessfile("","rw");
這個randomaccessfile寫的方式:insert模式

它將檔案中的內容,固定成byte陣列,這樣子去定位,如果要

寫東西進去的話,就是在byte對應的元素上面寫,也就是覆蓋對應位置的位元組,也就是insert模式。它並不能拓展空間

乙個簡單的插入內容的方法:將插入點,後面的檔案儲存在temp檔案中

file file = file.createtempfile("temp", null);

file.deleteonexit();

fileinputstream fis = new fileinputstream(file);

fileoutputstream fos = new fileoutputstream(file);

raf.seek(positions[0]);

//將插入點後面的所有內容謄寫一遍,到temp中

byte buff = new byte[64];

int hasread = 0;

while ((hasread = raf.read(buff))>0)

//再回要插入的點,插入東西

raf.seek(positions[0]);

raf.write("我母雞啊".getbytes());

//插完之後,將後面的東西再謄寫回來

while ((hasread = fis.read(buff))>0)

raf.close();

fis.close();

fos.close();

ini檔案的簡單讀寫

ini檔案的結構 section1 keyword1 valuel keyword2 value2 section2 keyword3 value3 keyword4 value4 c 操作ini檔案使用的是windows系統自帶win32的api函式 writeprivateprofilestri...

golang的簡單檔案讀寫

本文將對 golang的io 操作進行簡單的介紹。1 建立新檔案 io.go 並寫入檔案。package main import os encoding csv func main f.writestring this is test file defer f.close 在gvim 的命令引數裡面...

golang的簡單檔案讀寫

本文將對 golang的io 操作進行簡單的介紹。1 建立新檔案 io.go 並寫入檔案。package main import os encoding csv func main f.writestring this is test file defer f.close 在gvim 的命令引數裡面...