Forums Register Login

New To Java Text area question

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
Don't forget to use the new keyword when invoking a constructor to initialize a new object.
new InputStreamReader(new InputStream(myTextArea.getText()));
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Got it! I needed to use a StringReader and pass that to a BufferedReader. It works. Thanks
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 683 times.
Similar Threads
JTextarea and JScrollPane
UnsupportedEncodingException: SJIS
Need help viewing text file in text area
java io question, conceptual query
BufferedReader.reset() - Can it take you to the start of the stream?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:35:00.