我正在尝试创建一个使用txt文件的android应用,将文件用“;”分割,创建包含txt部分的字符串数组,然后调用电报api并将每一部分作为单独的消息发送至聊天室。 我收到此错误:
error: unreported exception MalformedURLException; must be caught or declared to be thrown
error: unreported exception IOException; must be caught or declared to be thrown
我是Java的完全新手,我只是从网络上学习并结合在一起。如您所知,我不完全了解代码。 特别是这部分:
Scanner scanner = new Scanner("app/src/main/java/com/example/myapplication/pasteall.txt");
String content = scanner.useDelimiter("\\A").next();
String[] posts = content.split("\\|");
代码如下:
String apiToken = "";
String chatId = "";
String urlString = "https://api.telegram.org/bot"+apiToken+"/sendMessage?chat_id="+chatId+"&text=%s";
Scanner scanner = new Scanner("app/src/main/java/com/example/myapplication/pasteall.txt");
String content = scanner.useDelimiter("\\A").next();
String[] posts = content.split("\\|");
int numberOfPosts = posts.length;
int i = 0;
for (i = 0; i < numberOfPosts; i++) {
urlString = String.format(posts[i]);
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
}