输入banner图图片脚本导航/分类

java 输入输出IO流 RandomAccessFile文件的任意文件指针位置地方来读写数据

java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; /** * @ClassName RandomAccessFileExample * @projectName: object1 * @author: Zhangmingda * @description: XXX * date: 2021/4/18. */ public class RandomAccessFileExample { public static void main(String[] args) { String textFilePath = "输入输出文件读写/src/test/input/test.txt"; try(RandomAccessFile randomAccessFile = new RandomAccessFile(textFilePath,"r")) { //当前文件指针位置 System.out.println(randomAccessFile.getFilePointer()); //0 randomAccessFile.seek(3); System.out.println(randomAccessFile.getFilePointer()); //3 byte[] bytes = new byte[1024]; int len; while ((len = randomAccessFile.read(bytes)) != -1){ String str = new String(bytes, 0, len, "utf-8"); System.out.println(str); /** *槽,这是测试输入的,你知道么? * 不知道? * 不知道拉到。 */ } }catch (FileNotFoundException e){ e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); } } }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

java 输入输出IO流 RandomAccessFile文件的任意文件指针位置地方来读写数据

标签:put   就是   classname   tst   oid   读取   方法   project   zhang