0

我正在尝试将 atrace 的输出写入 sdcard。我在 app.App 中使用 getRuntime().exec()("atrace gfx > /storage/sdcard0/trace.txt")从应用程序运行它时。

4

1 回答 1

0

我通过从输入流中读取数据并将其写入文件来解决它

 try {


                        Process p = Runtime.getRuntime().exec("atrace -t 5 gfx");
                        p.waitFor();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        String line = reader.readLine();
                        File myFile = new File("/storage/sdcard0/trac.txt");
                        FileOutputStream f = null;

                        try {
                            f = new FileOutputStream(myFile);
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        }
                        PrintWriter pw = new PrintWriter(f);
                        while (line != null) {
                            pw.println(line);

                            //Toast.makeText(getBaseContext(), line, Toast.LENGTH_LONG).show();
                            line = reader.readLine();
                        }
                        pw.flush();
                        pw.close();
                        f.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
于 2015-03-13T06:36:02.837 回答