⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dial.java

📁 java实现adsl的自动拨号以及刷新网页功能
💻 JAVA
字号:
import java.io.*;
import java.net.*;
public class Dial
{    
    public static void main(String[] args) 
	{ 	
		try
		{	
			if(args.length < 4)
			{
				System.out.println("参数至少为四个:URL地址 ADSL连接名称 连接用户名 连接密码 [输出文件]");
				if(args.length > 0)
					for (int i = 0; i < args.length ; i++)
					{
						System.out.println(args[i] );
					}
				System.exit(0);
			}

			int liStatic;
			String lsURL = args[0];
			String connString = "rasdial.exe " + args[1] + " " + args[2] + " " + args[3];
			String disconnString = "rasdial.exe " + args[1] + " DISCONNECT";
			String outFile = "";
			if(args.length > 4)
				outFile = args[4];
			
		
			Process p1 = Runtime.getRuntime().exec(connString);
			liStatic = p1.waitFor();    
			if(liStatic == 0)
				System.out.println("Connect Done.");    
			else
				System.out.println("Connect Error.");    
			
			DownLoadPages(lsURL,outFile);
			Thread.currentThread().sleep(3000);
			 
			Process p2 = Runtime.getRuntime().exec(disconnString);
			liStatic = p2.waitFor();    
			if(liStatic == 0)
				System.out.println("DisConnect Done.");    
			else
				System.out.println("DisConnect Error.");  
		}
		catch (Exception ex)
		{
			System.out.println("参数错误:URL地址 ADSL连接名称 连接用户名 连接密码 [输出文件]");
			ex.printStackTrace();
		}
		
	}    


	public static void DownLoadPages(String urlStr, String outPath)
    {
        int chByte = 0;
        URL url = null;
        HttpURLConnection httpConn = null;
        InputStream in = null;
        FileOutputStream out = null;
		String outString = null;
        try
        {
            url = new URL(urlStr);
            httpConn = (HttpURLConnection) url.openConnection();
            HttpURLConnection.setFollowRedirects(true);
            httpConn.setRequestMethod("GET"); 
            httpConn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)"); 
            
            // logger.info(httpConn.getResponseMessage());
            in = httpConn.getInputStream();
			if(outPath!=null && outPath!="")
			{
				out = new FileOutputStream(new File(outPath));
				chByte = in.read();
				while (chByte != -1)
				{
					out.write(chByte);
					chByte = in.read();
				}
			}
			
			BufferedReader inBuffer = null;
			StringBuffer sb = new StringBuffer();
			inBuffer = new BufferedReader(new InputStreamReader(in));
			String inputLine;
			while ((inputLine = inBuffer.readLine()) != null) 
			{
				sb.append(inputLine);
				sb.append("\n");
			}
			System.out.println(sb.toString());
        }
        catch (MalformedURLException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                out.close();
                in.close();
                httpConn.disconnect();
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
        }
    }
}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -