1. There is no reason to initialize process objects to zero.
Just do:
Process p = r.exec(str);
Process p1 = r.exec(str1);
While you're on it, better variable names would help
2. You can improve performance by reading and writing more than 1 character at a time:
3. You can explicitly specify encodings, and not use the default platform.
InputStreamReader reader = new InputStreamReader (p1.getInputStream (), inputCharsetName);
BufferedReader br = new BufferedReader(reader);
FileOutputStream fos = new FileOutputStream("this.txt", true);
Writer writer = new OutputStreamWriter(fos, outputCharsetName);
source
share