Can't authenticate with Java's HttpURLConnection?

You are getting a 401 Unauthorized response meaning that the OAuth token is probably wrong.

HttpURLConnection will throw an IOException if you call getInputStream() when the status response code (getResponseCode()) is not between 200 and 299. If you get a response outside of that range you should be calling getErrorStream() instead. By doing so you should be able to read the error message that twitch responded with.