import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* 对一个文件的内容进行加密
* @author DELL
*
*/
public class RandomAccessFileTest {
public static void main(String[] args) throws FileNotFoundException {
File f = new File("e://abc","data.txt");
byte[] bf = new byte[(int)f.length()];
RandomAccessFile rf = new RandomAccessFile(f, "rw");
try {
rf.read(bf);
for(int i=0;i<bf.length;i++){
bf[i] =(byte)( bf[i] + 12);
}
rf.setLength(0);
rf.write(bf);
rf.seek(3);
System.out.println((char)rf.read());
} catch (IOException e) {
e.printStackTrace();
}
}
}
【流】RandomAccessFile类
最新推荐文章于 2024-05-15 15:29:20 发布