File copying

BufferedReader inFile = new BufferedReader (new FileReader (sorc_path));

BufferedReader otFile = new BufferedReader (new FileReader (desn_path));

int c;

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

otFile.write ((char)c);

inFile.close ();

otFile.close ();

I get a error while compiling this code. In the line otFile.write (), char is to be pased. how to convert a int to a char value.

[424 byte] By [Mohamed_Thasneema] at [2007-11-27 11:01:50]
# 1

BufferedReader inFile = new BufferedReader (new FileReader (sorc_path));

BufferedReader otFile = new BufferedReader (new FileReader (desn_path));

What is the problem with the above code if one of those streams is suppossed to be a writer? Don't you think you should possibly use BufferedWriter and FileWriter instead of BufferedReader and FileReader for the writer?

Edit: Also, if you are going to use the simple read() and write(char) methods, you would possibly be better off using a simple FileInputStream and FileOutputStream directly rather than than the Buffered and File Reader and Writer classes.

masijade.a at 2007-7-29 12:39:23 > top of Java-index,Java Essentials,New To Java...
# 2

> Edit: Also, if you are going to use the simple

> read() and write(char) methods, you would possibly be

> better off using a simple FileInputStream and

> FileOutputStream directly rather than than the

> Buffered and File Reader and Writer classes.

Note that those methods of BufferedReader/Writer use buffering as well.

Anyway, what about using java.nio.channels.FileChannel ?

TimTheEnchantora at 2007-7-29 12:39:23 > top of Java-index,Java Essentials,New To Java...
# 3

> you would possibly be better off using a simple FileInputStream and FileOutputStream

Almost certainly, unless you are 100% sure that this code will only ever be applied to text files. You can't normally make that guarantee. Also raw copying via Input/OutputStreams will be much faster than all the implied character decoding/encoding of Readers and Writiers.

ejpa at 2007-7-29 12:39:23 > top of Java-index,Java Essentials,New To Java...