Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

chararraywriter  RSS feed

 
yasir badshah
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have already send u this
import java.io.*;
class a{
static public void main(String[] args)throws Exception{
CharArrayWriter caw=new CharArrayWriter();
caw.write(65);
caw.close();
caw.writeTo(new FileOutputStream"c:\\yasir.txt"));
}}
this is not writting in file tell me what i do.
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several problems with your code:
1) It has a syntax error, it is missing an open paren before the file name.
2) It doesn't compile because CharArrayWriter.writeTo() takes a Writer not an OutputStream.
3) You don't flush and close the File, which causes the character not to be written to the file.
Here is some code that works:

Out of curiosity, why are you using the CharArrayWriter? You could write to the FileWriter directly without the intermediate buffer.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!