IntelliJ Java IDE
The moose likes I/O and Streams and the fly likes chararraywriter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "chararraywriter" Watch "chararraywriter" New topic
Author

chararraywriter

yasir badshah
Greenhorn

Joined: Mar 14, 2002
Posts: 5
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

Joined: Dec 03, 2001
Posts: 125
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.
 
 
subject: chararraywriter
 
Threads others viewed
Clustering an application by jboss produced this:
Socket answer in multiple parts, Client receive only 1
charArrayWriter
How can final and transient be used in a variable declaraion?
protected field access error
jQuery in Action, 2nd edition