Here you can find the source of patchInfoPList(final File infoPList, final String executable)
public static boolean patchInfoPList(final File infoPList, final String executable) throws IOException
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean patchInfoPList(final File infoPList, final String executable) throws IOException { if (!infoPList.exists()) return false; String contents = readFile(infoPList); final Pattern pattern = Pattern.compile(".*<key>CFBundleExecutable</key>[^<]*<string>([^<]*).*", Pattern.DOTALL | Pattern.MULTILINE); final Matcher matcher = pattern.matcher(contents); if (!matcher.matches()) return false; contents = contents.substring(0, matcher.start(1)) + executable + contents.substring(matcher.end(1)); writeFile(infoPList, contents);/* w w w . jav a 2s.c om*/ return true; } protected static String readFile(final File file) throws IOException { final StringBuilder builder = new StringBuilder(); final BufferedReader reader = new BufferedReader(new FileReader(file)); for (;;) { final String line = reader.readLine(); if (line == null) break; builder.append(line).append('\n'); } reader.close(); return builder.toString(); } protected static void writeFile(final File file, final String contents) throws IOException { final File result = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".new"); final FileOutputStream out = new FileOutputStream(result); out.write(contents.getBytes()); out.close(); result.renameTo(file); } }