public static void copyWithVariableSubstitution(File source, File target, Map<String,String> variables, String varPrefix, String varSuffix) throws IOException {
BufferedReader reader = null;
BufferedWriter writer = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(source)));
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(target)));
String line = reader.readLine();
while (line != null) {
line = substitute(line, variables, varPrefix, varSuffix);
writer.write(line + "\n");
line = reader.readLine();