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 8794257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:13:39+00:00 2026-06-13T23:13:39+00:00

ive tried many different things and this is the only thing that has worked

  • 0

ive tried many different things and this is the only thing that has worked with reading one line from a file so far…

try{

        FileInputStream fstream = new FileInputStream("./Saves/Body.sav");
        BufferedReader br = new BufferedReader(new InputStreamReader(infstream);
        String strLine;    
        while ((strLine = br.readLine()) != null)   {      
        System.out.println(strLine);
        w1.Body = strLine;
        }  
        in.close();
          }catch (Exception e){//Catch exception if any
        System.err.println("Error: " + e.getMessage());
        }

I am trying to create a load function so i can load text from a file onto a string onto a jTextArea… Without any sort of openfiledialog

  • 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-13T23:13:39+00:00Added an answer on June 13, 2026 at 11:13 pm

    I’d personally use Guava:

    File file = new File("Saves", "Body.sav");
    String text = Files.toString(file, Charsets.UTF_8);
    

    That’s assuming it’s a UTF-8 file, of course. Adjust accordingly.

    Your current code has a number of issues:

    • It creates a DataInputStream for no obvious reason
    • You probably don’t gain much from using BufferedReader
    • You’re not specifying the character encoding, so you’re getting the platform default, implicitly, which is almost never a good idea.
    • You’re closing in which is in the middle of the chain of inputs for some reason… I’d expect to close either br or fstream
    • You’re only closing in if there’s no exception (use a finally block or a try-with-resources statement if you’re using Java 7)
    • You appear to have a field called Body, violating Java naming conventions
    • You’re catching Exception rather than IOException – prefer to catch specific exceptions
    • You’re “handling” the exception by effectively ignoring it, which is almost never appropriate. (The code which reads a file is very rarely the right code to decide what to do with an exception.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried so many different things. The point I'm at right now is this:
I've tried many different things, but I cant seem to get rid of this
I've researched this many hours and tried a lot of different things to figure
How do I use SplitLayoutPanel with UIBinder? I've tried so many different things but
I've tried many different things but none is working. I have a picture (let
I have done all kinds of research and tried many different things. I know
I'm tring to create a search based on date. I've tried so many different
I've searched and searched and tried many different ways, but I can't seem to
I've tried many functions already, but I simply can't figure this out. The right
I've tried many variations of this command: idle.py -e filepath , but it simply

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.