在java中,我需要从“http://www.mysite.com/text.txt”获取什么代码到扫描程序,该扫描程序尽可能少地解析网站中包含的结果文本。
答案 0 :(得分:8)
Scanner sc = new Scanner(new URL("http://www.mysite.com/text.txt").openStream());
答案 1 :(得分:5)
URL yahoo = new URL("http://www.yahoo.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(
yahoo.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
<强>参考强>
答案 2 :(得分:4)
取自here,未经过测试
URLConnection connection = new URL("http://www.mysite.com/text.txt").openConnection();
String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();
答案 3 :(得分:1)
一个HTTP GET
:(使用Java 8)
String doc = new Scanner(new URL(strUrl).openStream(), "UTF-8").useDelimiter("\\A").next();