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

  • Home
  • SEARCH
  • 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 8068401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:40:23+00:00 2026-06-05T12:40:23+00:00

I was wondering how I can go about reading a text file into an

  • 0

I was wondering how I can go about reading a text file into an array, the text file would contain something along the lines of:

string:string:string
string:string:string
string:string:string
etc

(string:string:string being on a single line)

  • 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-05T12:40:25+00:00Added an answer on June 5, 2026 at 12:40 pm

    UPDATE:

    I think you might want to read a file into an array but you don’t know set the size of an array. You can use a java.util.ArrayList for that and then convert it to an array.

    FileReader fin = new FileReader(fileName);
    Scanner src = new Scanner(fin);
    ArrayList<String> lines = new ArrayList<String>();
    src.useDelimiter(":");
    
    while (src.hasNext()) {
        lines.add(src.nextLine());
        // replace above line with array
    }
    String[] lineArray = new String[lines.size()];
    lines.toArray(lineArray);
    

    You can use the java.util.Scanner class and then use the useDelimiter function.

    FileReader fin = new FileReader(fileName);
    Scanner src = new Scanner(fin);
    
    src.useDelimiter(":");
    
    while (src.hasNext()) {
        System.out.println(src.next());
        // replace above line with array
    }
    

    Example here

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

Sidebar

Related Questions

I'm wondering how can I put a header into my PDF file, cause I've
I was reading about CopyOnWriteArrayList and was wondering how can I demonstrate data race
I did some reading about Gearman and i am wondering if it can be
I am wondering how I can go about stopping a dialog from opening if
I'm wondering that how much worried I should be about data types. I can
Can anyone recommend a fast way to sort the contents of a text file,
I'm reading my algorithms text book, and I'm reading about recurrence relations and finding
I've been reading about drupal install profiles, and I'm wondering if there's much of
I was reading about this EntityProxy feature in GWT 2.1+ and was wondering if
I am reading a book about Java and it says that you can declare

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.