String urlString = "https://api.telegram.org/bot%s/sendMessage?chat_id=%s&text=%s";
String apiToken = "123example";
String chatId = "@example";
String text = arrayGames[i];
urlString = String.format(urlString, apiToken, chatId, text);
URL url = null;
try {
url = new URL(urlString);
} catch (MalformedURLException e) {
e.printStackTrace();
}
URLConnection conn = url.openConnection();
StringBuilder sb = new StringBuilder();
InputStream is = new BufferedInputStream(conn.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String inputLine = "";
while ((inputLine = br.readLine()) != null) {
sb.append(inputLine);
}
urlString = String.format(urlString,
URLEncoder.encode(apiToken, "UTF-8"),
URLEncoder.encode(chatId, "UTF-8"),
URLEncoder.encode(text, "UTF-8"));