package org.fan.Sendsms;import java.net.*;
import java.io.*;public class Sendnow
{
public void Sendsms(){};
public void Send(String des,String Content) throws IOException
{
Sendsms(des,Content);
}
public void Send(String [] des,String Content) throws IOException
{
for(int i=0;i<des.length;i++)
{
Sendsms(des[i],Content);
}
}
public void Sendsms(String des,String Content)
throws java.io.IOException
{
try
{
URL sms = new URL("http://202.120.107.211:8800/?PhoneNumber="+des+"&Text="+URLEncoder.encode(Content,"GB2312")+"&charset=GB2312" );
sms.openStream( );
System.out.println("sms发送完毕");
} catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}
}需求的API是Send(String des,String Content,Date date),新加参数date实现定期执行我的想法是用timer.schedule(Task,date,0)的方法实现,但不知道这里的以上代码定义成这里的Task求教
import java.io.*;public class Sendnow
{
public void Sendsms(){};
public void Send(String des,String Content) throws IOException
{
Sendsms(des,Content);
}
public void Send(String [] des,String Content) throws IOException
{
for(int i=0;i<des.length;i++)
{
Sendsms(des[i],Content);
}
}
public void Sendsms(String des,String Content)
throws java.io.IOException
{
try
{
URL sms = new URL("http://202.120.107.211:8800/?PhoneNumber="+des+"&Text="+URLEncoder.encode(Content,"GB2312")+"&charset=GB2312" );
sms.openStream( );
System.out.println("sms发送完毕");
} catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}
}需求的API是Send(String des,String Content,Date date),新加参数date实现定期执行我的想法是用timer.schedule(Task,date,0)的方法实现,但不知道这里的以上代码定义成这里的Task求教
解决方案 »
- WARN JDBCExceptionReporter:100和101 - SQL Error: 1064, SQLState: 42000
- swt 的图形缩放如何实现抗锯齿?
- 请问个CSS的基本问题
- 怎样获取jar包内的文件路径?高手帮忙啊
- 接着求助:直接用文本编辑器编辑Java?是用记事本吗?怎么用啊?
- 高手来帮我一下,一个小程序
- 有讲Jcreator怎么调试的文章吗?也请高手指导了。
- 求教:为什么ResultSet对象调用getDate方法得到的结果转换为字符窜时,时间数据全是零?
- 寻找 sql server7.0 的jdbc driver 及连接方法?
- 请问如何从"byte[]"生成一个Image对象?JDK版本1.2!
- 两道JAVA多项选择题~~
- jdbc初学提问,请高手不惜赐教
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run(){
//add your code here to send your msg;
}
}, date, 0);
}继承并重写TimerTask里的run方法,就可以用timer.schedule(...)来指定时间触发它。
thx
我试了下,好象有点问题,
public void run(){}因为是inner class而得不到des,Content的传值,
还有继承TimerTask时也报了异常
麻烦看看是否有误,代码和异常如下public class Sendnow extends TimerTask
{
public void Sendsms(){}; public void Send(String des,String Content,Date date) throws IOException
{
Sendsms(des,Content,date);
} public void Sendsms(String des,String Content,Date date)
throws java.io.IOException
{
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
try
{
System.out.println(des+Content+"sms发送完毕");
}
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}
}, date, 0);
}
}报错:
Sendnow.java:10: Sendnow is not abstract and does not override abstract method r
un() in java.util.TimerTask
public class Sendnow extends TimerTask
^
Sendnow.java:33: local variable des is accessed from within inner class; needs t
o be declared final
System.out.println(des+Content+"sms发送完毕");
^
{
public void Sendsms()
{
}; public void Send(String des, String Content, Date date) throws IOException
{
Sendsms(des, Content, date);
} public void Sendsms(String des, String Content, Date date) throws java.io.IOException
{
Timer timer = new Timer(); final String str1= des;
final String str2= Content;
timer.schedule(new TimerTask()
{
public void run()
{
try
{
System.out.println(str1 + str2 + "sms发送完毕");
}
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}
}, date, 0);
}
}
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;public class Sendnow {
String theDes;
String theContent; public void Sendsms() {
}; public void Send(String des, String Content, Date date) throws IOException {
Sendsms(des, Content, date);
} public void Sendsms(String des, String Content, Date date)
throws java.io.IOException {
theDes = des;
theContent = Content;
Timer timer = new Timer(); timer.schedule(new TimerTask() {
public void run() {
System.out.println(Sendnow.this.theDes + Sendnow.this.theContent + "sms发送完毕");
}
}, date, 0);
}
}