FileInputStream类

时间:2018-02-15 20:07:31

标签: android

我正在Android中编写APP。我想将一个String传递给FileInputStream()。它编译得很好但是一旦运行我就会抛出异常并退出应用程序。我正确格式化了String Variable 任何建议都将不胜感激。

代码:

 // External storage 
    File Root = Environment.getExternalStorageDirectory();

    // Desire this   
    String CompletePath = (Root + "/PIL_SYNECT_TEST_PLAN/Ready_for_Execution" +   gVTruckSpecificSubFolder + "/" + gVFileToBeUsed);

    // debug msg
    Log.i(TAG, "onClick  CompletePath ------------------------>:" + CompletePath);

    //InputStream stream this is the way I need it to be
    FileInputStream stream = new FileInputStream(CompletePath);

    // Not hardcode in a string. However this works but is not how this needs to be
    FileInputStream stream = new FileInputStream("/storage/emulated/0/PIL_SYNECT_TEST_PLAN/Ready_for_Execution/C5 Daily Inspection List.json");

以下是Logcat消息:

 02-15 14:25:51.928 23346 23346/com.example.t0028919.person_in_looptesttool    I/TomsMessage:      onClick      CompletePath ------------------------ >:/storage/emulated/0/PIL_SYNECT_TEST_PLAN/Ready_for_Execution/C-5 DV123/C5 Daily Inspection List.json
    02-15 14:25:51.928 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err: java.io.FileNotFoundException: /storage/emulated/0/PIL_SYNECT_TEST_PLAN/Ready_for_Execution/C-5 DV123/C5 Daily Inspection List.json
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:  (No such file or directory)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at java.io.FileInputStream.open(Native Method)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:146)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:99)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at com.example.t0028919.person_in_looptesttool.MainActivity$2.onClick(MainActivity.java:256)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at android.view.View.performClick(View.java:6257)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at android.widget.TextView.performClick(TextView.java:11149)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at android.view.View$PerformClick.run(View.java:23705)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at android.os.Handler.handleCallback(Handler.java:751)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
    02-15 14:25:51.929 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at android.os.Looper.loop(Looper.java:154)
    02-15 14:25:51.930 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6780)
    02-15 14:25:51.930 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
    02-15 14:25:51.930 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
    02-15 14:25:51.930 23346-23346/com.example.t0028919.person_in_looptesttool W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
    02-15 14:25:51.930 23346-23346/com.example.t0028919.person_in_looptesttool D/AndroidRuntime: Shutting down VM
    02-15 14:25:51.930 23346-23346/com.example.t0028919.person_in_looptesttool E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                                 Process: com.example.t0028919.person_in_looptesttool, PID: 23346

0 个答案:

没有答案