这个代码在一个类中,它从一个网站获取源代码。我希望得到代码并在另一个类中的jTextArea中打印出来,但我不知道如何做到这一点。如何在另一个类中导出此源代码?
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);
}
}在另一个类中,我有一个带有以下代码的按钮:
try{
Connect();
} catch(Exception e) {
}发布于 2015-05-12 19:45:52
在第二节课上,你会打电话给
try{
ClassA.Connect();
} catch(Exception e) {
}其中ClassA是定义公共静态()的类的名称。注意,按照惯例,方法名应该以小写开头,因此它应该是公共静态()。
https://stackoverflow.com/questions/30199859
复制相似问题