Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:31:28+00:00 2026-06-13T20:31:28+00:00

I am curious what the most efficient way is to read a text file

  • 0

I am curious what the most efficient way is to read a text file (do not worry about size, it is reasonably small so java.io is fine) and then dump its contents into a JTextArea for display.

E.g. can I somehow consume the entire file in a single string and then use JTextArea.setText to display it or should I read line by line or byte arrays and populate them into a StringBuffer and then set the text area to that?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:31:29+00:00Added an answer on June 13, 2026 at 8:31 pm

    You can use JTextComponent.read(Reader, Object) and pass it a FileReader. Just do this:

    Java 7 — try-resource block

    try (FileReader reader = new FileReader("myfile.txt")) {
        textArea.read(reader, null);
    }
    

    Java 6 — try-finally block

    FileReader reader = null;
    try {
        reader = new FileReader("myfile.txt");
        textArea.read(reader, null);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was curious what the most efficient way to swap two elements in an
Just curious, what's the most pythonic/efficient way to determine if sequence of 3 characters
I am curious on the most efficient way to query exclusion on sql. E.g.
I'm curious about the reason why all most payment gateway site use clear text
Something I'm curious about.. What would be most efficient to cache the generation of,
I am curious with current technology, what would be the most efficient way to
Just curious about the maximum file size limit provided by some popular file systems
I am curious as to the best practices/most efficient way to structure my data.
I'm trying to determine what is the most efficient way to load videos into
I am learning Hadoop recently, and I am very curious about why most of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.