title: How to use two java.lang.Runtimes in the same Method?
body: <p>I want to use two <code>Runtime</code> in same method. The second  uses the result of the first. I return  the results of  in two files (<code>*.txt</code>). The result of execution of the first is ok, but the file of the second is empty.</p>
  
  <p>The code used is given below:</p>
  
  <pre><code>public void applicationpackage() {
          try {
              Process process = Runtime.getRuntime().exec(
                      new String[] { "/bin/sh", "-c",
                              "ls " + pathPackage + "/*.apk" });
              process.waitFor();
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                      process.getInputStream()));
              File f = new File(pathPackage + "/packagename.txt");
              PrintWriter writer = new PrintWriter(f, "UTF-8");
              String line = reader.readLine();
              while ((line != null)) {
                  System.out.println(line);
                  applicationPackage.add(line);
                  writer.println(line);
                  line = reader.readLine();
                  Process p = Runtime.getRuntime().exec(new String[]{
                          "/bin/sh", "-c", "cut -d. -f2,3 &lt;&lt;&lt;" + line
                  });
                  p.waitFor();
                  BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream())); 
                  File file = new File(pathPackage +"/application.txt");
                  PrintWriter w = new PrintWriter(file, "UTF-8");
                  String l = r.readLine();
                  while(l!= null){
                      w.println(l);
                      w.println("toto");
                      l = r.readLine();
                  }
  
                  name+= "cut -d. -f2,3 &lt;&lt;&lt;" + line +" &amp;";
  
                  System.out.println("toto" + name);
              }
              System.out.println("toto" + name);
              writer.close();
  
  
          } catch (IOException | InterruptedException e1) { }
  
  }
  </code></pre>