Java定时获取网络资源
import java.awt.*; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import java.util.Scanner; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class vb { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println("请输入访问的地址:"); String add=sc.next(); ScheduledExecutorService ex = Executors.newScheduledThreadPool(30); ex.scheduleAtFixedRate(new Runnable() { @Override public void run(){ try { // URL ur = new URL("https://www.baidu.com/"); // URL ur = new URL("https://blog.csdn.net/qq_39663113"); // URL ur = new URL("https://blog.csdn.net/qq_39663113/article/details/87990708"); URL ur = new URL(add); URLConnection op = ur.openConnection(); InputStream input = op.getInputStream(); byte[] b=new byte[1024]; int len=0; if(input!=null){ while((len=input.read(b))!=-1){ System.out.print(new String(b)); } Toolkit.getDefaultToolkit().beep(); } } catch (Exception e){ } } },0,4, TimeUnit.SECONDS) ; } }
Java定时获取网络资源
最新推荐文章于 2024-09-23 09:43:46 发布