Can somebdoy explain the output for this program?

Why is the value in the following program being read as 255 instead of -1 ?

The intent behind this program was to check whether the FileInputStream would be able to read -1 from the file, which btw is also the return value of read() when EOF is reached.

import java.io.IOException;

import java.io.FileInputStream;

import java.io.FileOutputStream;

class TestFileInputOutputStream

{

public static void main(String[] args) throws Exception

{

FileOutputStream fos = new FileOutputStream (" testfos.txt");

FileInputStream fis = new FileInputStream (" testfos.txt");

try

{

for (int i=0;i<10 ;i++ )

{

fos.write((byte)-1);//writing -1

}

int c ;

while ( (c=fis.read()) != -1)

{

System.out.print(c);//prints 255

}

}

finally

{

if (fos!= null)

{

fos.close();

}

if (fis!= null)

{

fis.close();

}

}//finally

}

}

[1017 byte] By [harsha_ava] at [2007-11-27 8:55:31]
# 1
oops!! my mistake, assumed there's an overloaded byte method!!!!
harsha_ava at 2007-7-12 21:16:45 > top of Java-index,Core,Core APIs...