e / trace:错误打开跟踪文件:没有这样的文件或目录(2)

时间:2013-07-23 16:46:52

标签: android trace

我在项目android应用程序上工作.. 我的应用程序使用file.txt进行处理。 我发现打开跟踪文件时出错:

 No such file or directory (2) when running my application.

清单我有完整的互联网访问权限。 我将file.txt保存在res/raw/file.txt中 代码行中没有错误。 我使用的是OS 4.1(果冻豆) android“sdk”21

任何帮助都将不胜感激。

然后我再次尝试使用虚拟机器人4.2.2 ......但结果也是错误

public List<String> read() {
    List<String> ls = new ArrayList<String>();
    try {          
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("res/raw/katadasar.txt");
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        StringBuffer stringBuffer = new StringBuffer();
        String strLine;
        //Read File Line By Line
        while ((strLine = bufferedReader.readLine()) != null) {
        // Print the content on the console
        // System.out.println(strLine);
        ls.add(strLine.trim().toLowerCase());
        }
        //Close the input stream
        inputStreamReader.close();
        } catch (Exception e) {//Catch exception if any
        System.err.println("Error: " + e.getMessage());
        }
        return ls;
}

logcat的

 07-24 03:38:38.710: D/dalvikvm(790): Not late-enabling CheckJNI (already on)
 07-24 03:38:39.060: I/dalvikvm(790): Turning on JNI app bug workarounds for target SDK     version 9...
 07-24 03:38:39.470: E/Trace(790): error opening trace file: No such file or directory (2)
 07-24 03:38:39.700: D/dalvikvm(790): GC_FOR_ALLOC freed 65K, 8% free 2403K/2608K,           paused 29ms, total 31ms
 07-24 03:38:39.720: I/dalvikvm-heap(790): Grow heap (frag case) to 3.944MB for 1536016-byte allocation
 07-24 03:38:39.770: D/dalvikvm(790): GC_FOR_ALLOC freed <1K, 6% free 3902K/4112K, paused 49ms, total 49ms
 07-24 03:38:39.820: D/dalvikvm(790): GC_CONCURRENT freed <1K, 6% free 3902K/4112K, paused 4ms+3ms, total 55ms
 07-24 03:38:40.120: D/(790): HostConnection::get() New Host Connection established 0x2a18c160, tid 790
 07-24 03:38:45.919: D/dalvikvm(790): GC_CONCURRENT freed 1505K, 38% free 2808K/4484K, paused 12ms+57ms, total 256ms
 07-24 03:38:54.389: D/dalvikvm(790): GC_CONCURRENT freed 121K, 31% free 3104K/4484K, paused 73ms+95ms, total 300ms
 07-24 03:38:58.909: D/dalvikvm(790): GC_CONCURRENT freed 269K, 28% free 3255K/4484K, paused 75ms+9ms, total 150ms
 07-24 03:38:58.909: D/dalvikvm(790): WAIT_FOR_CONCURRENT_GC blocked 69ms
 07-24 03:38:59.389: D/dalvikvm(790): GC_CONCURRENT freed 202K, 23% free 3477K/4484K, paused 75ms+8ms, total 138ms
 07-24 03:38:59.389: D/dalvikvm(790): WAIT_FOR_CONCURRENT_GC blocked 57ms
 07-24 03:38:59.669: D/dalvikvm(790): GC_CONCURRENT freed 575K, 24% free 3409K/4484K, paused 74ms+8ms, total 144ms
 07-24 03:38:59.679: D/dalvikvm(790): WAIT_FOR_CONCURRENT_GC blocked 33ms
 07-24 03:39:00.530: D/dalvikvm(790): GC_CONCURRENT freed 387K, 23% free 3492K/4484K, paused 29ms+89ms, total 223ms

1 个答案:

答案 0 :(得分:0)

要在原始文件夹中打开文件,你可以试试这个:

InputStream is = ctx.getResources().openRawResource(R.raw.katadasar);
InputStreamReader isr = new InputStreamReader(is);

此外,您应该更改捕获中的代码:

catch (Exception e) {//Catch exception if any
    System.err.println("Error: " + e.getMessage());
}

,打印正确的错误:

catch (Exception e) {//Catch exception if any
    Log.e("YourTag", "Error:" +  e.getLocalizedMessage() );
}

尝试上面的代码(带有corret error logcat输出),如果它不起作用,请更新logcat输出以尝试找到错误