从SD卡读取错误

时间:2016-06-06 04:41:50

标签: android text-files

这里是接收意图的代码,文件uri.i只需要读取文件中的数据并在文本视图中显示 *有没有其他方法可以做到这一点?

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Uri path = data.getData();
    String paths = path.toString();


    if (requestCode == PICK_FROM_FILE && resultCode == RESULT_OK) {


        // File file = new File(Environment.getExternalStorageDirectory(), data.getData().toString());

        String extension = paths.substring(paths.lastIndexOf("."));
        if(extension.equals(".txt"))
        {
            ContentResolver cr = this.getContentResolver();
            File f=new File(String.valueOf(path));
            StringBuilder string =new StringBuilder();
            try
            {
                BufferedReader br=new BufferedReader(new FileReader(f));
                String line;
                while((line=br.readLine())!=null)
                {

                   string.append(line);
                    string.append('\n');

                }
                br.close();
            } catch (IOException e) {

                e.printStackTrace();
            }

        }
        else
        {
            Toast.makeText(getApplicationContext(),"please choose text file",Toast.LENGTH_LONG).show();
        }
    }

}

提前感谢您的帮助......

我的错误日志是:(这是我项目中发生的警告)

    -06 10:17:24.573 1266-1591/? E/Resources: RunTimeException
                                            android.content.res.Resources$NotFoundException: Resource ID #0x7f02005d
                                            at android.content.res.Resources.getValue(Resources.java:2480)
                                            at android.content.res.Resources.startRC(Resources.java:1095)
                                            at android.app.ActivityThread$mRunnable.run(ActivityThread.java:2969)
                                            at      java.lang.Thread.run(Thread.java:818)
   06-06 10:17:24.673 1294-1294/? E/MotionRecognitionManager: mSContextService = null
   06-06 10:17:24.673 1294-1294/? E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@1aae3e6
   06-06 10:17:27.548 2725-3333/? E/ClipboardUIManager: Failed to get ClipboardService
   06-06 10:17:28.083 2725-2828/? E/libprocessgroup: failed to kill 1 processes for processgroup 22037
   06-06 10:17:28.953 1668-1668/? E/Zygote: MountEmulatedStorage()
   06-06 10:17:28.953 1668-1668/? E/Zygote: v2
   06-06 10:17:28.968 1668-1668/? E/SELinux: [DEBUG] get_category: variable seinfo:   untrusted sensitivity: NULL, cateogry: NULL
   06-06 10:17:29.383 1668-1668/? E/SysUtils: ApplicationContext is null in      ApplicationStatus

0 个答案:

没有答案