*
The moose likes Beginning Java and the fly likes OutputStreamWriter store value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OutputStreamWriter store value" Watch "OutputStreamWriter store value" New topic
Author

OutputStreamWriter store value

Je Th
Greenhorn

Joined: Dec 03, 2003
Posts: 12
Hello!
I want to store the value of OutputStreamWriter into an array or String. But this code dosent work at all, Im getting an error at the "output += writer.write(ch);"
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi,
I'm really not sure what you're trying to do. First, there are two things wrong with that line of code. First, write() returns "void", meaning nothing. You can't append "void" to a String -- you have to have actual data to append. So this line won't compile.
It also won't compile because the += operator reads the existing value and appends to it, but you never initialize the String to a starting value. Java won't let you read an uninitialized variable.
Strings aren't appropriate for holding the binary data that ObjectOutputStream produces; note that, unlike C, in Java bytes and characters are distinct data types.
Can you tell me what you actually want to accomplish? I'm pretty sure you shouldn't be using ObjectOutputStream at all, since I don't see any objects being serialized here. Let me know what you actually need to do, as opposed to what you're trying to code, here, and I will try to point you in the right direction.


[Jess in Action][AskingGoodQuestions]
Je Th
Greenhorn

Joined: Dec 03, 2003
Posts: 12
Ok here is the deal. I want to make an consoleapp. I want to ask the user to eneter two things. First and lastname. The value of the users choice of letters are supose to be stored in a string or array. So if I type Je then Th it would be String myVar = "Je Th";
Thanks for your answer!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: OutputStreamWriter store value