• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New To Java Text area question

 
Steve Gebert
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Steve Gebert
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it! I needed to use a StringReader and pass that to a BufferedReader. It works. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic