PDA

Click to See Complete Forum and Search --> : InputStreamReader & OutputStreamWriter


Dillinger4
Oct 1st, 2001, 04:17 PM
I thought InputStreamReader is supposed to convert bytes to characters and OutputStreamWriter is supposed to convert characters to bytes thereby bridging the gap between byte and character streams. But when i run this code i just get the same character output that i read in the first place just outputted to another file.
Shouldent the output be bytes instead of characters?

import java.io.*;

public class X{
public static void main(String[] args){
try{
FileReader fr = new FileReader("C:\\Java\\test.txt");
File file = new File("C:\\Java\\test.txt");
FileOutputStream fos = new FileOutputStream("C:\\Java\\test1.txt");
OutputStreamWriter osw = new OutputStreamWriter(fos);

char[] buffer = new char[(int)file.length()];

fr.read(buffer);
osw.write(buffer);
osw.close();
}catch(Exception e){System.out.println(e);}
}
}