Skip to content

Instantly share code, notes, and snippets.

@kpradeep12
Created October 2, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpradeep12/4804bbcde77e55ab91ed3fb90445cc4e to your computer and use it in GitHub Desktop.
Save kpradeep12/4804bbcde77e55ab91ed3fb90445cc4e to your computer and use it in GitHub Desktop.
public class DesktopUtility {
public static void main(String[] args) throws URISyntaxException, IOException {
Desktop desktop = java.awt.Desktop.getDesktop();
if(!Desktop.isDesktopSupported())
return;
// Opens composing window of default mail client
desktop.mail(new URI("mailto:<email address>"));
// Launches default browser
desktop.browse(new URI("http://techstackjava.com/"));
// Opens a folder containing the file
desktop.browseFileDirectory(new File("/opt"));
// Opens a file in associate application
desktop.open(new File("/opt/users.txt"));
// Prints a file with native desktop printing facility
desktop.print(new File("/opt/report.txt"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment