简体   繁体   中英

RandomAccessFile.write: EBADF (Bad file descriptor)

I'm getting java.io.IOException: write failed: EBADF (Bad file descriptor) when trying to write a RandomAccessFile .

    RandomAccessFile raf;
    try {
        raf = new RandomAccessFile("foo", "r");
        byte bytes[] = "test".getBytes(StandardCharsets.US_ASCII);
        raf.write(bytes);
        raf.close();
    } catch (FileNotFoundException e){
    } catch (IOException e){
    }

Why do I get this exception?

创建RandomAccessFile时使用“rw”而不是“r”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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