Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutputStreamWriter store value

 
Je Th
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Je Th
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic