从网站上获取文本并将其设置为 Java 中的字符串

Getting text off a website and set it as a string in Java

我正在尝试从网站获取一些文本并将其设置为 Java 中的字符串。

我在 Java 中几乎没有网络连接经验,希望得到一些帮助。

这是我目前得到的:

static String wgetURL = "http://www.realmofthemadgod.com/version.txt";
static Document Version;
static String displayLink = "http://www.realmofthemadgod.com/AGCLoader" + Version + ".swf";

public static void main(String[] args) throws IOException{
    Version = Jsoup.connect(wgetURL).get();
    System.out.println(Version);
    JOptionPane.showMessageDialog(null, Version, "RotMG SWF Finder", JOptionPane.DEFAULT_OPTION);
}

我正在尝试使用 Jsoup,但我一直收到启动错误(启动时出现问题)。

您的问题与 Jsoup 无关。

您正在尝试使用 Version 创建字符串,而 Version 未定义。

将您的代码更改为:

public static void main(String[] args) throws IOException{
    String url = "http://www.realmofthemadgod.com/version.txt"
    Document doc = Jsoup.connect(url).get();
    System.out.println(doc);
    // query doc using jsoup ...
}