これにそれを実行する必要があります。彼は
HttpURLConnection connection = null;
URL url;
InputStream is = null;
try {
url = new URL("https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&client_secret=" + appSecret + "&grant_type=client_credentials");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept-encoding", "gzip");
is = connection.getInputStream();
String content = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8));
String[] tokens = content.split("=");
System.out.println(tokens[1]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (is != null) try {
is.close();
} catch (IOException e) {}
connection.disconnect();
}
私は質問で本当にこのinsn'tを知っているが、比較のために:
InputStream is = process.getInputStream();
String content = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8));
is.close();
そしてここでは、完全な使用の実際の生活の例です。あなたはIOUtilsでそれを行うだろう方法です - IMOは少しクリーナーである:完了時
HttpURLConnection connection = null;
URL url;
InputStream is = null;
try {
url = new URL("https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&client_secret=" + appSecret + "&grant_type=client_credentials");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept-encoding", "gzip");
is = connection.getInputStream();
String value = IOUtils.toString(is);
if (!Strings.isNullOrEmpty(value)) {
String[] splits = value.split("=");
System.out.println(splits[1]);
}
} catch (IOException e) {
} finally {
IOUtils.closeQuietly(is);
connection.disconnect();
}
これは、ストリームを閉じていない - それだけでことを行いますInputSupplier – Zugwalt