Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Need help viewing text file in text area

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a text file how do i view the contents in a text area?

I understand this:
textarea1.setText(x);

(but x has to be a string?)

Do I have to convert a text file to string then to view it in this way?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Conrad,
you are right, you can just give .setText a String, as the documentation says:

void setText(String t)
Sets the text of this TextComponent to the specified text.


setText() is a method inherited from JTextComponent. There is method that's for you

void read(Reader in, Object desc)
Initializes from a stream.



I was just working on this too, so here is a snippet of my code:

In my case, I had Textfiles with special characters (for instance: catalan and romanian characters), so I needed Unicode/ UTF-8 encoding. The important class to process the encoding information is InputStreamReader. If you don't need it like this, you are done with:


That's it! Have a nice day
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic