This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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
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
Don't forget to use the new keyword when invoking a constructor to initialize a new object. new InputStreamReader(newInputStream(myTextArea.getText()));
Joined: Jan 29, 2003
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.