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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:38:55+00:00 2026-05-14T02:38:55+00:00

How to save text file content to different arrays? my text file content is

  • 0

How to save text file content to different arrays?

my text file content is like this;

12 14 16 18 13 17 14 18 10 23
pic1 pic2 pic3 pic4 pic5 pic6 pic7 pic8 pic9 pic10
left right top left right right top top left right
100 200 300 400 500 600 700 800 900 1000

how can I save each line into different array?
e.g.

line 1 will be saved in an array1
line 2 will be saved in an array2
line 3 will be saved in an array3
line 4 will be saved in an array4
  • 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-14T02:38:56+00:00Added an answer on May 14, 2026 at 2:38 am

    Solution 1

    List<String[]> arrays = new ArrayList<String[]>(); //You need an array list of arrays since you dont know how many lines does the text file has
    try {
            BufferedReader in = new BufferedReader(new FileReader("infilename"));
            String str;
            while ((str = in.readLine()) != null) {
               String arr[] = str.split(" ");
               if(arr.length>0) arrays.add(arr);
            }
            in.close();
        } catch (IOException e) {
        }
    

    At the end arrays will contain every array. In your example arrays.length()==4

    To iterate over the arrays:

    for( String[] myarr : arrays){
       //Do something with myarr
    }
    

    Solution 2: I don’t think this is a good idea but if you are sure the file always is going to contain 4 lines you can do this

    String arr1[];
    String arr2[];
    String arr3[];
    String arr4[];
    try {
            BufferedReader in = new BufferedReader(new FileReader("infilename"));
            String str;
            str = in.readLine();
            arr1[] = str.split(" ");
            str = in.readLine();
            arr2[] = str.split(" ");
            str = in.readLine();
            arr3[] = str.split(" ");
            str = in.readLine();
            arr4[] = str.split(" ");
    
            in.close();
        } catch (IOException e) {
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to save some simple text data to a file from my Silverlight
I have an asp.net app and I am trying to save a text file
I've got this wired problem, I cannot get the content from the file and
I am trying to save an NSMutableArray containing text to a plist file using
Possible Duplicate: How to write content on a text file using java? Is it
I have a text file containing the following content: 0 12 1 15 2
I have created a text file to save the error in that created file.
I have my web browsers set to save what I type into text boxes
I save stuff in an Isolated Storage file (using class IsolatedStorageFile). It works well,
To save network traffic I'd like to compress my data. The only trick is

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.