This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InputStream/BufferedReader with JTextArea

 
Martin Clifford
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again all!
I'm trying to find a way to open an ASCII .txt file, read it, then output it to a JTextArea component. I thought the following code would do the trick, but it doesn't do anything (at least that I can see):

Anyone have any words of advice on this? I'm gonna go back to working on it, but look forward to hearing some opinions! )
I'm excited to almost have a working app now! It can save files, change font values, and all that stuff.
If anyone wants to see it when it's done, just let me know )
Adios, pardners.
[ December 06, 2002: Message edited by: Martin Clifford ]
 
Paul Stevens
Ranch Hand
Posts: 2823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing your code to:

[ December 06, 2002: Message edited by: Paul Stevens ]
 
Martin Clifford
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, still nothing.
Right now, to get the filename, I'm just using this:

Now here's what might be wrong... it gets the filename, and that's all well and good, but I don't think that contains a pointer to the directory the file was chosen from. Could this be the reason? Back to work on it, thanks for the reply.
 
Martin Clifford
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I figured out that it was because the file path wasn't complete.
Now I have this:

The only problem with that is, that it only works on the C:\ drive, since if the file is in My Documents getCurrentDirectory() doesn't add root dirs to the path. Not only this, but readLine() doesn't seem to preserve newline chars, so I have to try another method of reading in the data.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFileChooser's getSelectedFile() method returns a File object that already has all the info you need - just use that:

Calling additional methods like getFileName() just separates the filename info from the directory info - which is unnecessary, and the source of your current problems.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic