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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:22:05+00:00 2026-06-16T18:22:05+00:00

I am trying to read csv file which is located in SD card but

  • 0

I am trying to read csv file which is located in SD card but when i select the file i get a File not found Exception.The below is my code.

Intent intent = new Intent();             //Browse the file
    intent.setType("file/csv");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select csv"),
            SELECT_CSV_Dialog);

 if (resultCode == RESULT_OK) {
 if (requestCode == 1) {
  data = result.getData();//data is the URI
 System.out.println("res "+data);
 if (data.getLastPathSegment().endsWith("csv") || data.getLastPathSegment().endsWith("CSV")) {       
     try {
         File f = new File(data.getPath());//this is where i get the file not found             
         FileInputStream  fis =new FileInputStream(f);   
            fis = this.openFileInput(data.toString());
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(fis));
                             String line;
            while ((line = reader.readLine()) != null) {
                String[] RowData = line.split(",");
                System.out.println("row  "+RowData.length);
                if(RowData.length==2){                      

        Toast.makeText(Importt.this, "Schema Supported", Toast.LENGTH_SHORT).show();
                    break;
                }else{
    Toast.makeText(Importt.this, "Schema not Supported", Toast.LENGTH_SHORT).show();
                }
            }}

This is where i get the error “File f = new File(data.getPath());”.

Any suggestions are highly appreciated.

  • 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-16T18:22:06+00:00Added an answer on June 16, 2026 at 6:22 pm

    Use the below code to read the data from csv file . it worked for me .

    try
       {
        List<String> list = new ArrayList<String>();
        String line;
    
        String fileName = "/mnt/sdcard/test.csv";
        FileReader reader = new FileReader(fileName);
        BufferedReader bufrdr = new BufferedReader(reader);
        line = bufrdr.readLine();
        while (line != null) {
            list.add(line);
            line = bufrdr.readLine();
        }
        bufrdr.close();
        reader.close();
    
        String[] array = new String[list.size()];
        list.toArray(array);
    
        for (int i = 0; i < list.size(); i++) {
            System.out.println(" 22222222 0 0 " + list.get(i).toString() );
        }
    
     }
      catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    

    For SD-CARD Checking use the following lines :

    static public boolean hasStorage(boolean requireWriteAccess) {
        //TODO: After fix the bug,  add "if (VERBOSE)" before logging errors.
        String state = Environment.getExternalStorageState();
        Log.v(TAG, "storage state is " + state);
    
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            if (requireWriteAccess) {
                boolean writable = checkFsWritable();
                Log.v(TAG, "storage writable is " + writable);
                return writable;
            } else {
                return true;
            }
        } else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            return true;
        }
        return false;
    }
    

    EDIT 2 use the below code to bring the file from sdcard.

    private static final int FILE_SELECT_CODE = 0;
    
        private void showFileChooser() {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
            intent.setType("*/*"); 
            intent.addCategory(Intent.CATEGORY_OPENABLE);
    
            try {
                startActivityForResult(
                        Intent.createChooser(intent, "Select a File to Upload"),
                        FILE_SELECT_CODE);
            } catch (android.content.ActivityNotFoundException ex) {
                // Potentially direct the user to the Market with a Dialog
                Toast.makeText(this, "Please install a File Manager.", 
                        Toast.LENGTH_SHORT).show();
            }
        }
    

    You would then listen for the selected file’s Uri in onActivityResult() like so:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            switch (requestCode) {
                case FILE_SELECT_CODE:      
                if (resultCode == RESULT_OK) {  
                    // Get the Uri of the selected file 
                    Uri uri = data.getData();
                    Log.d(TAG, "File Uri: " + uri.toString());
                    // Get the path
                    String path = FileUtils.getPath(this, uri);
                    Log.d(TAG, "File Path: " + path);
                    // Get the file instance
                    // File file = new File(path);
                    // Initiate the upload
                }           
                break;
            }
        super.onActivityResult(requestCode, resultCode, data);
        }
    
    
    public static String getPath(Context context, Uri uri) throws URISyntaxException {
            if ("content".equalsIgnoreCase(uri.getScheme())) {
                String[] projection = { "_data" };
                Cursor cursor = null;
    
                try {
                    cursor = context.getContentResolver().query(uri, projection, null, null, null);
                    int column_index = cursor
                    .getColumnIndexOrThrow("_data");
                    if (cursor.moveToFirst()) {
                        return cursor.getString(column_index);
                    }
                } catch (Exception e) {
                    // Eat it
                }
            }
    
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }
    
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a csv file, of which a sample: datetime,check,lat,lon,co_alpha,atn,status,bc 2012-10-27
I am trying to read this .csv file and here is an example of
I am trying to read a CSV file with accented characters with Python (only
I'm trying to read a csv file into R that has date values in
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
I'm trying to read in a (tab separted) csv file in R. When I
I am trying to read and sort a csv file that has data that
Hi am having a csv file in my hand and am trying to read
I am trying to use the CSVhelper plugin to read an uploaded CSV file.
Trying to read an RSS and select information using Linq but can't seem 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.