当我尝试填充随机访问文件时遇到问题,在使用循环时它会在达到第 924 个字节时停止写入,所以当我尝试用“-”填充 2500 个字节时,它只填充 924字节。这是我使用的代码,希望有人能告诉我我做错了什么
public class Hashing {
private RandomAccessFile espacio;
public Hashing() throws FileNotFoundException, IOException{
File amigos = new File("Texto");
String r = "rws";
espacio = new RandomAccessFile(amigos ,r);
this.estableceEspacioLlenado();
}
public void estableceEspacioLlenado() throws IOException{
int a = 0;
while(a<2500){
if(a>=241 && a%241==0){
espacio.writeBytes("\n");
a++;
}
else{
espacio.writeBytes("-");
a++;
}
}
}
}
输出文件:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------