Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3757912
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:04:49+00:00 2026-05-19T10:04:49+00:00

I would like to make it clear and draw some parallels between FileOutputStream and

  • 0

I would like to make it clear and draw some parallels between FileOutputStream and FileChannel right now.

So first of all, it seems like the most efficient way to write file with standart Java io is to use FileOutputStream which is wrapped with BufferedOutputStream. Because it automatically flushes, when the internal buffer is overflowed. It is convenient to be able to do single writes (single bytes, floats, etc.) as well as array ones and to be not worried about speed. The only thing you should never forget is to close it (to perform the final flush). Benefits of using BufferedOutputStream wrapper are evident and must have for everyone (I hope).

Now about FileChannel. FileChannel has force method, which is an equivalent to flush in FileOutputStream, isn’t it? And javadocs clearly say, that you should use it to be sure that your changes have been made to the target file. But, I don’t understand when and why should I use it, if there is no “BufferedFileChannel” wrapper. In other words, where is buffering for FileChannel? Is it automatic and hidden in FileChannel itself like in BufferedOutputStream? If not, then why on earth would I need force method, since there is nothing to force (all changes are already applied to file after using write method) and do I have to implement buffering by myself?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:04:50+00:00Added an answer on May 19, 2026 at 10:04 am

    BufferedOutputStream have a cache in java, which FileChannel do not.

    However, FileChannel do have OS-Level cache. In which .force() is the same as fsync / fdatasync.

    In OpenJDK 6 src/solaris/native/sun/nio/ch/FileChannelImpl.c

      157 JNIEXPORT jint JNICALL
      158 Java_sun_nio_ch_FileChannelImpl_force0(JNIEnv *env, jobject this,
      159                                        jobject fdo, jboolean md)
      160 {
      161     jint fd = fdval(env, fdo);
      162     int result = 0;
      163 
      164     if (md == JNI_FALSE) {
      165         result = fdatasync(fd);
      166     } else {
      167         result = fsync(fd);
      168     }
      169     return handle(env, result, "Force failed");
      170 }
    

    Read this blog if you want to know more how OS works in this level.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just would like to make clear, I cannot find straight answer. C# is general
I have a clean Eclipse Java SDK. I would like to make it suitable
I would like make an extension method for the generic class A which takes
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make a LaTeX document with two tables of contents, like:
I would like to make a class where the client side (proxy) of the
I would like to make my drivers to install on x64 Windows without the
I would like to make an entire inline formset within an admin change form
I would like to make a php script that can capture a page from
I would like to make a query which needs to compare an property's property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.