@Testpublic void test2() throws Exception {
RandomAccessFile read = new RandomAccessFile("Test922示例图.png", "rw");RandomAccessFile write = new RandomAccessFile("Test922示例图复制.png", "rw");int i ;while (( i = read.read())!= -1){
write.write(i);}read.close();write.close();}
附加指定位置插入数据
@Testpublic void test() throws Exception {
RandomAccessFile randomAccessFile = new RandomAccessFile("Test927.txt", "rw");randomAccessFile.seek(3);byte[] bytes = new byte[2];StringBuilder stringBuilder = new StringBuilder();int len;while ((len = randomAccessFile.read(bytes)) != -1) {
stringBuilder.append(new String(bytes, 0, len));}System.out.println(stringBuilder);randomAccessFile.seek(3);randomAccessFile.write("xyz".getBytes());randomAccessFile.write(stringBuilder.substring(0).getBytes());randomAccessFile.seek(0);while ((len = randomAccessFile.read()) != -1) {
System.out.print((char) len);}randomAccessFile.close();}