Android-从Google Drive中选择CSV文件并用java解析

Android-从Google Drive中选择CSV文件并用java解析,java,android,csv,google-drive-android-api,opencsv,Java,Android,Csv,Google Drive Android Api,Opencsv,我正在尝试从Google drive加载CSV文件,并用java解析它。但每当我选择文件时,它都会显示异常:找不到文件 下面是我的实现代码: 选择器意图代码: Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("text/csv"); //XML file only intent.addCategory(Intent.CATEGORY_OPENABLE); try

我正在尝试从Google drive加载CSV文件,并用java解析它。但每当我选择文件时,它都会显示异常:找不到文件

下面是我的实现代码:

选择器意图代码:

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("text/csv");   //XML file only
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try
    {
        startActivityForResult(Intent.createChooser(intent, "Select"), 100);
    } catch (android.content.ActivityNotFoundException ex)
    {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, "Drive Not Found", Toast.LENGTH_SHORT).show();
    }
激活结果:

   @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode)
    {
        case 100:
            {
            if (resultCode == RESULT_OK)
            {
                //onImport(new File(data.getData().getPath()));
                String filePath = null;
                Uri uri = data.getData();

                File file = new File(uri.toString());
                if (file.exists()) {
                    //Do something
                    System.out.println("Exists");
                    proImportCSV(new File(data.getData().getPath()));
                }
                else
                {
                    System.out.println("Not Exists");
                }

            }
        }
    }
}
使用CSVReader解析CSV

   private void proImportCSV(File from)
{
    try
    {
        // reading CSV and writing table
        CSVReader reader = null;
        try
        {
            reader = new CSVReader(new FileReader(from));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        String[] nextLine;
        try {
            while ((nextLine = reader.readNext()) != null) {
                // nextLine[] is an array of values from the line
                System.out.println(nextLine[0] + nextLine[1] + "etc...");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
请告诉我为什么我得到文件找不到错误。另外,我是否正确解析csv?如果不正确,请详细告诉我正确的答案


提前谢谢

我用bufferReader解析了它,一切都很完美

        Uri uri = data.getData();    
            BufferedReader mBufferedReader = null;
            String line;

             try
                {
                    InputStream inputStream = getContentResolver().openInputStream(uri);
                    mBufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                    while ((line = mBufferedReader.readLine()) != null)
                    {
                        System.out.println("LLLLL: "+ line);
                    }
                    mBufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }    

我用bufferReader解析了它,一切都很完美

        Uri uri = data.getData();    
            BufferedReader mBufferedReader = null;
            String line;

             try
                {
                    InputStream inputStream = getContentResolver().openInputStream(uri);
                    mBufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                    while ((line = mBufferedReader.readLine()) != null)
                    {
                        System.out.println("LLLLL: "+ line);
                    }
                    mBufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }