⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e171. writing and appending a bytebuffer to a file.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
If you have one or more ByteBuffers to dump to a file, use a FileChannel. 
    // Write bbuf to filename
    ByteBuffer bbuf = getMyData();
    File file = new File("filename");
    
    // Set to true if the bytes should be appended to the file;
    // set to false if the bytes should replace current bytes
    // (if the file exists)
    boolean append = false;
    
    try {
        // Create a writable file channel
        FileChannel wChannel = new FileOutputStream(file, append).getChannel();
    
        // Write the ByteBuffer contents; the bytes between the ByteBuffer's
        // position and the limit is written to the file
        wChannel.write(bbuf);
    
        // Close the file
        wChannel.close();
    } catch (IOException e) {
    }

 Related Examples 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -