title: Run cat command in Android
body: <p>I want to concatenate two files in android. I did this from the Terminal Emulator app using the command <code>cat file1 file2 &gt; output_file</code>. But it does not work when I try to execute it from my code. </p>
  
  <p>This is the code that I used to execute the command.</p>
  
  <pre><code>    public String exec() {
      try {
  
          // Executes the command.
          String CAT_COMMAND = "/system/bin/cat /sdcard/file1 /sdcard/file2 &gt; /sdcard/output_file";
          Process process = Runtime.getRuntime().exec(CAT_COMMAND);
  
          // Reads stdout.
          // NOTE: You can write to stdin of the command using
          //       process.getOutputStream().
          BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
          int read;
          char[] buffer = new char[4096];
          StringBuffer output = new StringBuffer();
          while ((read = reader.read(buffer)) &gt; 0) {
              output.append(buffer, 0, read);
          }
          reader.close();
  
          // Waits for the command to finish.
          process.waitFor();
  
          return output.toString();
      } catch (IOException e) {
  
          throw new RuntimeException(e);
  
      } catch (InterruptedException e) {
  
          throw new RuntimeException(e);
      }
  }
  </code></pre>
  
  <p>I have given the permission to write to external storage in the manifest. What am I missing?</p>