This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Need help viewing text file in text area Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help viewing text file in text area" Watch "Need help viewing text file in text area" New topic
Author

Need help viewing text file in text area

Conrad McLaughlin
Greenhorn

Joined: Jan 31, 2006
Posts: 27
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?
Daniel Palombo
Greenhorn

Joined: Feb 28, 2006
Posts: 10
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help viewing text file in text area
 
Similar Threads
How can I get a View reference from a JEditorPane
JSF tree view GUI component and tree node actions
Browsing HTML and XML files in text area
how to string search ?
How to import Image file