• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

InputStream/BufferedReader with JTextArea

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing your code to:

[ December 06, 2002: Message edited by: Paul Stevens ]
 
Martin Clifford
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic