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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:35:36+00:00 2026-05-26T12:35:36+00:00

I have a bunch of strings that I’m writing to a file: private void

  • 0

I have a bunch of strings that I’m writing to a file:

private void writeScoreToFile(BlastScore result)
    {
        try{
            FileWriter fstream = new FileWriter(getFilesDir() + CaptureActivity.BLAST_SCORES,true);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(Integer.toString(result.getBlastScore()));
            out.close();
        }catch (Exception e){
            System.err.println("Write Error: " + e.getMessage());
        }
    }

I would like to read it back in as a List.

private List<String> getArrayFromFile(String filename) throws IOException
    {
        FileReader fileReader = new FileReader(getFilesDir() + filename);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        List<String> lines = new ArrayList<String>();
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            lines.add(line);
        }
        bufferedReader.close();
        return lines;
    }

The list that is being written is:

100
96
100
96
100

When I print the List it looks like

10-28 21:22:31.130: I/System.out(936): Last Score: 1009610096100

Here is the code I am using to print it:

try {
            List<String> blastScores = getArrayFromFile(CaptureActivity.BLAST_SCORES);
            System.out.println("Last Score: " + blastScores.get(blastScores.size()-1));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.err.println("Read Error: " + e.getMessage());
        }

I’m trying to get the n-1 element.

I’m not sure what I’m doing wrong.

  • 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-05-26T12:35:37+00:00Added an answer on May 26, 2026 at 12:35 pm

    When you are writing the Integers or Integer Strings you are not putting a new line character after each output. Hence, your file has only one line of data, which line you are getting as a continuous String…
    To fix, add a line separator like write.newLine() in between separate write() calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I have is a giant text file that contains a bunch of strings
I have a file with a bunch of strings that looks like this: new
I have a bunch of strings in a text file that have values in
I have a bunch of strings that are dependent on static dictionaries and each
I have a bunch of strings in perl that all look like this: 10
I'm writing a bunch of strings to a file using a string writer but
Say I have 5 collections that contain a bunch of strings (hundreds of lines).
I have a bunch of static Strings that I'd like to store in a
Basically I have a bunch of large strings that I want to remove spaces/punctuation/numbers
So I have a bunch of strings in records that include the '/' character,

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.