-2

I have this code and I was wondering if it was possible to input a search into google through my java program. For example when the user inputs google it will open google.com and the program will automatically fill the search in from another string they entered. For example if the userInput string was google.com:what year is it?

How could I make the program search "what year is it?" in the browser?

else if(userInput.contains("google.com")) {
    try {
        Desktop.getDesktop().browse(new URL("http://google.com").toURI());
    }           
    catch (Exception e) {}
}
takendarkk
  • 3,347
  • 8
  • 25
  • 37
user3166873
  • 85
  • 3
  • 10

1 Answers1

1

There is an API to search google programmatically. The API is called google custom search. For using this API, you will need an Google Developer API key and a cx key.

ltalhouarne
  • 4,586
  • 2
  • 22
  • 31
  • The example involves google but I'm just curious..would I not be able to enter a string into my program and get it to print out in notepad? or even word for example – user3166873 Feb 06 '14 at 15:30
  • You can use a buffered reader to take a string from a file, then you can user a buffered writer to write a string to a file. – ltalhouarne Feb 06 '14 at 15:34