• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

chararraywriter

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic