需要:我需要java中的代码,它显示在Web浏览器中浏览的所有内容(例如:google)。 此代码应在应用程序(虚拟桌面)中执行。
我的申请: - 我的项目基于用户行为分析,在java中完成。 - 我制作了一个虚拟桌面,其中包括google,youtube等许多应用程序。 - 用户从虚拟桌面进入应用程序进行浏览(例如:google)。 - 我想显示用户在应用程序中搜索过的内容(例如:google,youtube)。
请帮我解决java代码问题。
注意:我有一个用于从Java(虚拟桌面)打开Google应用程序的代码。从虚拟桌面打开Google应用程序后,我需要保存在Google中搜索的内容吗?
答案 0 :(得分:1)
以下内容可能对您有所帮助......
import java.net.*;
import java.io.*;
public class JavaUrlConnectionReader
{
public static void main(String[] args)
{
String output = getUrlContents("www.google.com");
System.out.println(output);
}
private static String getUrlContents(String theUrl)
{
StringBuilder content = new StringBuilder();
try
{
// create a url object
URL url = new URL(theUrl);
// create a urlconnection object
URLConnection urlConnection = url.openConnection();
// wrap the urlconnection in a bufferedreader
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
// read from the urlconnection via the bufferedreader
while ((line = bufferedReader.readLine()) != null)
{
content.append(line + "\n");
}
bufferedReader.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return content.toString();
}
}