public static void main(String[] args) throws IOException { if (args.length < 1 || args.length > 2) { System.out.println("Usage: java -jar signer.jar unsigned.apk [signed.apk]"); return; } boolean replace = args.length < 2; File input = new File(args[0]), output = new File(replace ? args[0] + ".singed.apk" : args[1]); if (!input.exists() || !input.isFile()) { System.out.println( "Error: " + input.getName() + " is not exists! Full path: " + input.getAbsolutePath()); return; } if (output.exists()) { System.out.print("File " + output.getName() + " already exists! Overwrite? [N/y]: "); int b = System.in.read(); if (b == 'Y' || b == 'y') { output.delete(); } else { return; } } sign(input, output); if (replace) { input.delete(); output.renameTo(input); } }
public static void sign(String input, String output) { sign(new File(input), new File(output)); }