java如何调用RandomAccessFile读取txt文件第3个字节并替换成1,然后输出整个
发布网友
发布时间:2022-05-06 17:03
我来回答
共1个回答
热心网友
时间:2023-10-12 22:18
File file = new File("tcp.txt");
FileInputStream stream = new java.io.FileInputStream(file);
int pos =3;//从第几个字节开始读
int len = 1;//读几个字节
stream.skip(pos); //跳过之前的字节数
byte[] b = new byte[len];
stream.read(b);
System.out.print(new String(b));
stream.close();追问怎样将读取到的字符替换为“1”,并把整个字符串输出?
热心网友
时间:2023-10-12 22:18
File file = new File("tcp.txt");
FileInputStream stream = new java.io.FileInputStream(file);
int pos =3;//从第几个字节开始读
int len = 1;//读几个字节
stream.skip(pos); //跳过之前的字节数
byte[] b = new byte[len];
stream.read(b);
System.out.print(new String(b));
stream.close();追问怎样将读取到的字符替换为“1”,并把整个字符串输出?