Behavior of does not match the spec

Sean Chou zhouyx at
Thu Feb 17 08:46:03 UTC 2011

   I find there is a mismatch between the spec and the behavior of

   The spec reads: "The initial position of the returned channel will be
equal to the number of bytes written to the file so far unless this
stream is in append mode, in which case it will be equal to the size
of the file. "

   But we'll get size 0 in such situation. Here is the testcase:


public class  FileOutputStreamTest{
   public static void main(String args[]) throws Exception{
        File tmpfile = File.createTempFile("FileOutputStream", "tmp");
        FileOutputStream fos = new FileOutputStream(tmpfile, false);
        fos.write(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

        fos = new FileOutputStream(tmpfile, true);
        long size = fos.getChannel().position();
        if (10 != size){
               // This return value is 0, mismatching the spec
               System.out.println("Position Error Detected: except 10, but
was " + size);
// End of the testcase

    Any comments?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the core-libs-dev mailing list