| Author |
InputStream/BufferedReader with JTextArea
|
Martin Clifford
Greenhorn
Joined: Dec 02, 2002
Posts: 23
|
|
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 ]
|
Martin
|
 |
Paul Stevens
Ranch Hand
Joined: May 17, 2001
Posts: 2823
|
|
Try changing your code to: [ December 06, 2002: Message edited by: Paul Stevens ]
|
 |
Martin Clifford
Greenhorn
Joined: Dec 02, 2002
Posts: 23
|
|
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
Joined: Dec 02, 2002
Posts: 23
|
|
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
Joined: Jan 30, 2000
Posts: 18652
|
|
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'm not back." - Bill Harding, Twister
|
 |
 |
|
|
subject: InputStream/BufferedReader with JTextArea
|
|
|