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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:59:42+00:00 2026-06-10T11:59:42+00:00

I have a text file stored in sdcard.I want to copy the data from

  • 0

I have a text file stored in sdcard.I want to copy the data from text file in sdcard into a string array.I want to store data in string array and then later use that data in my autocompletetextview.My code is:

package com.example.pro2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ReadSettings();

            }
        });
    }
    public void ReadSettings(){

        try{             
            File sdcard = Environment.getExternalStorageDirectory();
            File file = new File(sdcard,"comm.txt");        
               FileInputStream fileIS = new FileInputStream(file);          
               BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));           
               String readString = new String();                


               String val[] = null;
               for(int i=0;i<5;i++)
               {
               while ((readString = buf.readLine()) != null) {
                   Log.d("line: ", readString);   
                   val[i] = readString;
                   Log.d("values", val[i]);
                   // u better use an ArrayList or you have to check if i < val.size
               }
               }

            } catch (FileNotFoundException e) {          
               e.printStackTrace();          
            } catch (IOException e){             
               e.printStackTrace();          
        }    
    } 
    }

But it is showing force close.Plz help.

  • 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-10T11:59:43+00:00Added an answer on June 10, 2026 at 11:59 am

    Not possibly an answer, please change here:

    ArrayList<String> val = new ArrayList();
                   int i=0;
    
                   while ((readString = buf.readLine()) != null) {
                       Log.d("line: ", readString);   
                       val.add(readString);
                       Log.d("values", val.get(i).toString());
               i++;
                       // u better use an ArrayList or you have to check if i < val.size
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have stored values retrieved from a text file into an array. Now am
I have the below contents from a .txt file stored into a string variable
I have a text file where data is stored as columns. How do I
I have a text file stored as a string variable. The text file is
I have a text read from a XML file stored in UTF8 encoding. C#
I am reading a string from an xml file stored on the sdcard that
I have a html file (contains some text and one image) stored @ /sdcard/test
I have a text file stored in my sql DB. in that .txt file
I have a text file containing a number of records. Each record is stored
I have a directory path stored in a text file, and I need to

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.