Changeset 1451 for trunk/java-utils/src/main/java/de/ugoe/cs/util
- Timestamp:
- 03/31/14 14:28:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-utils/src/main/java/de/ugoe/cs/util/FileTools.java
r1243 r1451 15 15 package de.ugoe.cs.util; 16 16 17 import java.io.BufferedWriter; 17 18 import java.io.File; 18 19 import java.io.FileInputStream; 19 20 import java.io.FileNotFoundException; 20 21 import java.io.FileReader; 22 import java.io.FileWriter; 21 23 import java.io.IOException; 22 24 import java.io.InputStreamReader; … … 99 101 return (new String(buffer)).split(splitString); 100 102 } 101 103 102 104 /** 103 105 * <p> 104 * Autocompletes a give path. The path must be absolute. Otherwise, autocompletion 105 * is not possible. 106 * Writes an array to a file using the toString function of its object. 107 * </p> 108 * 109 * @param array 110 * array that is written 111 * @param filename 112 * name of the output file 113 * @param separator 114 * separator string that is put between the array objects 115 * @param lineBreak 116 * if true, a new line is added after each array element and its separator 117 * @throws IOException 118 * see {@link BufferedWriter#write(String)}, {@link BufferedWriter#newLine()}, 119 * {@link BufferedWriter#flush()}, {@link BufferedWriter#close()}, 120 * {@link FileWriter#FileWriter(String)} 121 */ 122 public static <T> void writeArrayToFile(T[] array, 123 String filename, 124 String separator, 125 boolean lineBreak) throws IOException 126 { 127 BufferedWriter outputWriter = null; 128 outputWriter = new BufferedWriter(new FileWriter(filename)); 129 for (int i = 0; i < array.length; i++) { 130 outputWriter.write(array[i].toString()); 131 if (i < array.length - 1) { 132 outputWriter.write(separator); 133 if (lineBreak) { 134 outputWriter.newLine(); 135 } 136 } 137 } 138 outputWriter.flush(); 139 outputWriter.close(); 140 } 141 142 /** 143 * <p> 144 * Autocompletes a given path. The path must be absolute. Otherwise, autocompletion is not 145 * possible. 106 146 * </p> 107 147 * … … 113 153 File prefixFile = new File(prefix); 114 154 File parentDir = prefixFile.getParentFile(); 115 155 116 156 if (parentDir == null) { 117 157 // the prefix does not denote a path or denotes one of the root directories. … … 119 159 return prefix; 120 160 } 121 161 122 162 String[] completions = null; 123 163 124 164 if (parentDir.exists()) { 125 165 completions = parentDir.list(); 126 166 } 127 167 128 168 if (completions == null) { 129 169 completions = new String[0]; 130 170 } 131 171 132 172 String completedPrefix; 133 173 134 174 completedPrefix = StringTools.autocomplete(prefixFile.getName(), completions); 135 175 136 176 File completedFile = new File(parentDir, completedPrefix); 137 177 138 178 if (completedFile.exists() && completedFile.isDirectory()) { 139 179 return completedFile.getAbsolutePath() + File.separator;
Note: See TracChangeset
for help on using the changeset viewer.