📄 deadthread.java
字号:
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class DeadThread implements Runnable
{
String totalString;
Mail mail=new Mail();
String telephone;
String mailContent;
public DeadThread(Mail mail)
{
this.mail=mail;
}
public String ReadFile()
{
File file=new File("D:/mail.txt");
int len=(int)file.length();
byte [] buf=new byte[len];
try
{
FileInputStream in=new FileInputStream(file);
in.read(buf);
in.close();
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null,"读取文件mail.txt时出现错误!");
}
return new String(buf);
}
public void run()
{
totalString=ReadFile();
while(true)
{
String tempString=ReadFile();
if(tempString.contentEquals(totalString))
{
System.out.println("程序监测中");
try
{
Thread.sleep(5000);
}catch(InterruptedException e1)
{}
}
else
{
System.out.println("文件发生改变,群发短信");
totalString=ReadFile();
int len=totalString.length();
int top=(int)Math.floor(len/70);
DataConn conn=new DataConn();
try
{
conn.SqlQuery("select * from friends");
while(conn.rs.next())
{
int i;
telephone=conn.rs.getString("telphone");
for(i=0;i<top;i++)
{
mailContent=totalString.substring(i*70,i*70+70);
mail.SendMail(telephone,mailContent);
}
mailContent=totalString.substring(i*70);
mail.SendMail(telephone,mailContent);
}
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null,e1);
}
try
{
Thread.sleep(5000);
}catch(InterruptedException e1)
{}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -