This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes New To Java Text area question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "New To Java Text area question" Watch "New To Java Text area question" New topic
Author

New To Java Text area question

Steve Gebert
Greenhorn

Joined: May 07, 2004
Posts: 17
Hi - In advance thanks! I have figured out how to read a text file and put it into a text area. It is a multi line file that I now need to read one line at a time, parse the line and send it to a database. I have looked through this forum and think that I need a buffered reader and some type of stream reader but when I try to use them I get a error.
InputStreamReader aStream = new InputStreamReader(myTextArea);
br = new BufferedReader(aStream);
return br.readLine();
gives me a constructor error for InputStreamReader. I would really appreciate a few lines of code to get this started. Thanks
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
What argument does InputStreamReader expect in that constructor? Looks like you're passing it a TextArea and that's what it's complaining about.
InputStreamReader javadoc tells you what kind of stream it wants in its constructor. The name it gives you is an interface. If you follow the link to the javadoc for that interface you'll see a list of classes that implement the interface. One of those ought to jump out and grab your attention if you want to read a file.
I'm being vague so you can enjoy the hunt. Holler again if that was too vague. Have fun with this!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Steve Gebert
Greenhorn

Joined: May 07, 2004
Posts: 17
Well I guess I'm a little dense here. I tried the following;
InputStreamReader aStream = new InputStreamReader(InputStream(myTextArea.getText()));
BufferedReader br = new BufferedReader(aStream);
return br.readLine();
I now get "Error(256,55): method InputStream(java.lang.String) not found in class SNPReader.ReadFrame"
I admit that I took intro to Oracle Java last week so I seem to be in over my head so please bear with me.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Old Dog,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Don't forget to use the new keyword when invoking a constructor to initialize a new object.
new InputStreamReader(new InputStream(myTextArea.getText()));
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Ahh, that's just telling you you're missing "new" in front of the InputStream constructor. Once you get that, I'm betting it will tell you there is no constructor with a string argument. Or that InputStream is abstract (I said interface earlier, my bad) and you can't create one.
Look at the JavaDoc for InputStream, "direct known subclasses". See if there is one there that will read a file given the file name. Try that class where you have InputStream.
BTW: I'm guessing the textarea contains the name of the file you want to read? Is that right? If it actually contains the text you want to read we have to use a different subclass of InputStream.
Steve Gebert
Greenhorn

Joined: May 07, 2004
Posts: 17
Got it! I needed to use a StringReader and pass that to a BufferedReader. It works. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New To Java Text area question