• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is charS?

 
Tom Baker
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a mock exam I had a question dealing with "charS" does anyone have an idea what it is reference to. (the mock exam answer was vague, but said it had to do with inputstreamreader?)
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The DataOutputStream has a method writeChars(String s) which will write the String s, writing one char at a time. Since this is part of the OutputStream class it writes it in bytes so you get two bytes per char and once the entire string is written the counter written is incremented by twice the length of the string.
Bill
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bill.
perhaps you can help me. Why would I want to write a String using a DataOutputStream? I would think that I would always use a Writer of some sort, wrapped in a BufferedWriter and probably that wrapped in a PrintWriter.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randall, I wouldn't use DataOutputStream. That is what Readers and Writers are for. But the functionality is provided in DataOutputStream.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic