简体   繁体   English

只能使用RandomAccessFile写入直到第924个字节

[英]only can write until the 924th byte using RandomAccessFile

Im having a problem when i try to fill up a randomaccessfile, in using a loop for it and it stops writing when it reaches de 924th byte, so when i try to fill up 2500 bytes with "-" for example, it only fills 924 byte. 我在尝试填充随机访问文件时遇到问题,在使用它的循环时,当它到达de 924th字节时它停止写入,因此,例如,当我尝试使用“-”填充2500字节时,它仅填充924字节。 Here is the code that im using, hope someone can tell me what i am doing wrong 这是即时通讯使用的代码,希望有人可以告诉我我做错了什么

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++;
            }
        }
    }        
}

output file: 输出文件:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Perhaps the data is buffered and hasn't been flushed to disk. 也许数据已缓冲并且尚未刷新到磁盘。 Add a close() call at the end to ensure everything gets written. 在末尾添加一个close()调用以确保所有内容都被写入。

espacio = new RandomAccessFile(amigos ,r);
this.estableceEspacioLlenado();
espacio.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM