IOers,
I am correct in stating that a Reader reads 1 byte at a time? I tought it read by default 1 unicode (16 bit) char at a time. I wrote the following very simple
test program to write (using a stream) a byte followed by 3 chars. When I read these using a reader it seems to read one byte at a time (8 bits) not 16!
import java.io.*;
public class Test5
{
public static void main(
String[] args)
{
File f = new File("io2.txt");
try {
FileOutputStream fos = new FileOutputStream (f);
BufferedOutputStream bos = new BufferedOutputStream(fos);
DataOutputStream dos = new DataOutputStream (bos);
byte x = 69;
dos.writeByte(x);
dos.writeChars("ABC");
dos.close();
}
catch (IOException ioe) {System.out.println(ioe);}
try {
FileReader fr = new FileReader (f);
BufferedReader br = new BufferedReader (fr);
System.out.println((char)br.read()); // prints E
System.out.println((char)br.read()); // prints nothing
System.out.println((char)br.read()); // prints A
System.out.println((char)br.read()); // prints nothing
System.out.println((char)br.read()); // prints B
System.out.println((char)br.read()); // prints nothing
System.out.println((char)br.read()); // prints C
br.close();
}
catch (IOException ioe) {System.out.println(ioe);}
}
}
regards,
George