//ReadURLPage.java
import java.net.*;
import java.io.*;
public class ReadURLPage 
{
 public static void main(String[] args) throws Exception
 {
  URL ctgpc = new URL("http://www.ctgpc.com.cn/index.php");
  BufferedReader in = new BufferedReader(
     new InputStreamReader(
     ctgpc.openStream()));
  String pageLine;
  while((pageLine = in.readLine()) != null)
  {
    if(pageLine.indexOf("中国长江三峡工程开发总公司") != -1)
    {
      System.out.println(pageLine);
    }else
    {
      /* 请问,在这里怎么使用MsgSend这个类?
      *  MsgSend是一个公共类,它有四个参数,在Dos下用法如下:
      *  usage: java MsgSend <to> <from> <smtp> true|false
      */
    }
   
  }
  in.close();
 } 
}问题见上,MsgSend是一个发邮件的类,在命令行下可以单独使用,但如何用到ReadURLPage类中去呢?
请不吝赐教!

解决方案 »

  1.   

    StringTokenizer st = new StringTokenizer("java MsgSend to from smtp true");String[] envp = new String[6];
    for(int i=0; st.hasMoreTokens(); i++) {
             envp[i]= st.nextToken();
    }Runtime.getRuntime().exec(MsgSend,envp);
      

  2.   

    如果有MsgSend类源码,可以直接用MsgSend类!
    不行建议是使用javamail!
      

  3.   

    //ReadURLPage.java
    import java.net.*;
    import java.io.*;
    import java.util.*;public class ReadURLPage 
    {
     public static void main(String[] args) throws Exception
     {
      URL ctgpc = new URL("http://www.ctgpc.com.cn/index.php");
      BufferedReader in = new BufferedReader(
         new InputStreamReader(
         ctgpc.openStream()));
      String pageLine;
      while((pageLine = in.readLine()) != null)
      {
       if(pageLine.indexOf("中国长江三峡工程开发总公司") != -1)
       {
       //System.out.println(pageLine);  
       }else
       {
       StringTokenizer st = new StringTokenizer("java MsgSend [email protected] [email protected] email.ctgpc.com.cn false");
    String[] envp = new String[6];
    for(int i=0; st.hasMoreTokens(); i++) 
    {
        envp[i]= st.nextToken();
    }
    Runtime.getRuntime().exec(MsgSend,envp);
       }
       
      }
      in.close();
     } 
    }
    按照网友“ cathy97(做人要厚道)”的回复,我已将程序做了修改,但编译时仍然报错:
    “ReaderURLPage.java:28 : cannot resolve symbol
      symbol    : variable MsgSend
      location  : class ReadURLPage
                        Runtime.getRuntime().exec(MsgSend,envp);  1 error”请问这个错误如何解决呢?