public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println("Usage:  AddPerson ADDRESS_BOOK_FILE");
      System.exit(-1);
    }

    AddressBook.Builder addressBook = AddressBook.newBuilder();

    // Read the existing address book.
    try {
      FileInputStream input = new FileInputStream(args[0]);
      try {
        addressBook.mergeFrom(input);
      } finally {
        try { input.close(); } catch (Throwable ignore) {}
      }
    } catch (FileNotFoundException e) {
      System.out.println(args[0] + ": File not found.  Creating a new file.");
    }

    // Add an address.
    addressBook.addPeople(
      PromptForAddress(new BufferedReader(new InputStreamReader(System.in)),
                       System.out));

    // Write the new address book back to disk.
    FileOutputStream output = new FileOutputStream(args[0]);
    try {
      addressBook.build().writeTo(output);
    } finally {
      output.close();
    }
  }
public static void main ( String [ ] args ) throws Exception { if ( args . length != 1 ) { System . err . println ( "Usage:  AddPerson ADDRESS_BOOK_FILE" ) ; System . exit ( - 1 ) ; } AddressBook . Builder addressBook = AddressBook . newBuilder ( ) ; try { FileInputStream input = new FileInputStream ( args [ 0 ] ) ; try { addressBook . mergeFrom ( input ) ; } finally { try { input . close ( ) ; } catch ( Throwable ignore ) { } } } catch ( FileNotFoundException e ) { System . out . println ( args [ 0 ] + ": File not found.  Creating a new file." ) ; } addressBook . addPeople ( PromptForAddress ( new BufferedReader ( new InputStreamReader ( System . in ) ) , System . out ) ) ; FileOutputStream output = new FileOutputStream ( args [ 0 ] ) ; try { addressBook . build ( ) . writeTo ( output ) ; } finally { output . close ( ) ; } }
file.