---
category: swing
folder: Desktop
title: Desktopでブラウザを起動
tags: [Desktop, Html]
author: aterai
pubdate: 2007-02-19T16:02:04+09:00
description: JDK 6で導入されたDesktopを使ってブラウザを起動します。
image: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTKu9HhvrI/AAAAAAAAAWc/iMheiQnF4hQ/s800/Desktop.png
---
* Summary [#summary]
`JDK 6`で導入された`Desktop`を使ってブラウザを起動します。

#download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTKu9HhvrI/AAAAAAAAAWc/iMheiQnF4hQ/s800/Desktop.png)

* Source Code Examples [#sourcecode]
#code(link){{
if (Desktop.isDesktopSupported()) {
  try {
    Desktop.getDesktop().browse(new URI(href));
  } catch (IOException | URISyntaxException ex) {
    ex.printStackTrace();
  }
}
}}

* Explanation [#explanation]
- `Desktop`を使用することで拡張子に関連付けられたデフォルトのアプリケーションを起動可能
- `OS`毎に対応するアプリケーションを`Runtime.getRuntime().exec(String[])`で実行せずにブラウザなどを起動可能

* Reference [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/Desktop.html Desktop (Java Platform SE 8)]
//- [http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/ Using the Desktop API in Java SE 6]
- [http://www.oracle.com/technetwork/articles/javase/index-135182.html Using the Desktop API in Java SE 6]
- [[Browserを起動>Swing/BrowserLauncher]]

* コメント [#comment]
* Comment [#comment]
#comment
#comment