Java 从网站获取源代码

Java get Source code from Website

此代码在 class 中,它从网站获取源代码。我想获取代码并将其打印在另一个 class 中的 jTextArea 中,但我不知道该怎么做。我如何在另一个 class 中导出此源代码?

public static void Connect() throws Exception{

    URL url = new URL("https://www.google.com/");
    URLConnection spoof = url.openConnection();


    spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
    BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
    String strLine = "";

    while ((strLine = in.readLine()) != null){

        System.out.println(strLine);
    }

}

在另一个 class 中,我有一个带有此代码的按钮:

    try{
        Connect();
    } catch(Exception e) {

    }

在第二个class中,你会调用

try{
    ClassA.Connect();
} catch(Exception e) {

}

其中 ClassA 是 class 的名称,其中定义了 public static void Connect()。请注意,按照惯例,方法名称应以小写字母开头,因此应为 public static void connect().