- Timestamp:
- 12/10/09 03:59:38 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/ecj/framsticks/FramsticksUtils.java
r49 r50 4 4 import java.io.BufferedWriter; 5 5 import java.io.File; 6 import java.io.FileNotFoundException; 6 7 import java.io.FileReader; 7 8 import java.io.FileWriter; 9 import java.io.IOException; 8 10 import java.io.InputStreamReader; 9 11 … … 83 85 84 86 private String executeCommand(String command) { 85 String line;86 String result = "";87 88 87 if (debug) { 89 88 System.err.println("Executing command : " + command); 90 89 } 91 90 91 String result = new String(); 92 92 try { 93 93 File f = new File(directoryPath); 94 94 Process p = Runtime.getRuntime().exec(directoryPath + command, null, f); 95 95 BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); 96 while ((line = input.readLine()) != null) { 97 result += (line + '\n'); 98 } 99 input.close(); 96 result = readInput(input); 100 97 } catch (Exception ex) { 101 98 ex.printStackTrace(); … … 105 102 System.err.println("Result : " + result); 106 103 } 107 104 108 105 return result; 109 106 } … … 120 117 121 118 private String readFromFile(String filePath) { 122 String line; 123 String result = ""; 119 String result = new String(); 124 120 try { 125 121 BufferedReader input = new BufferedReader(new FileReader(filePath)); 122 result = readInput(input); 123 } catch (FileNotFoundException e) { 124 e.printStackTrace(); 125 } 126 return result; 127 } 128 129 private String readInput(BufferedReader input) { 130 StringBuilder result = new StringBuilder(); 131 132 try { 133 String line; 126 134 while ((line = input.readLine()) != null) { 127 result +=(line + '\n');135 result.append(line + '\n'); 128 136 } 129 137 input.close(); 130 } catch ( Exception ex) {138 } catch (IOException ex) { 131 139 ex.printStackTrace(); 132 140 } 133 141 134 return result; 142 //Delete last newline character 143 if (result.length() > 0) { 144 return result.substring(0, result.length() - 1); 145 } else { 146 return result.toString(); 147 } 135 148 } 136 149
Note: See TracChangeset
for help on using the changeset viewer.