一部分代码:
class mythread extends Thread{
/
被start()方法调用的主线程方法.
/
public void run()
{
dbwr();
}
/
该方法完成读文件,分析文件,插库,删除文件等全部功能.被线程主方法run()调用.
/
public synchronized void dbwr()
{
// File news = new File("./store/");
/
读入(./store/)路径
/
//File news = new File("./store/");
File news = new File("f:/store/");
/
存放所读的文件对象.
/
File arry[];
arry=news.listFiles();
int delete_i=0;
try{
if(arry.length<1){
this.sleep(60000);
sernews.insertthread();
this.stop();this.destroy();
}
this.sleep(1000);
/
一个用于判断文件是否结束的字节,如果结束,会自动返回-1.
/
byte temp[]=new byte[1];
/
读入没条新闻的分类个数.
/
byte class_total[]=new byte[4];
/
读入新闻类别.
/
byte class_id[]=new byte[4];
/
新闻的日期.
/
byte news_date[]=new byte[4];
/
新闻时间
/
byte news_time[]=new byte[4];
/
新闻标题的长度.
/
byte title_total[]=new byte[4];
/
新闻标题
/
byte news_title[]=new byte[1024];
/
新闻内容
/
byte news_content[]=new byte[653600];
/
新闻ID号,每条新闻去当前数据库中最大的ID号.
/
long news_id=0;
for(int i=0;i
System.out.print("文件名: "+arry.getName());
if(!arry.isFile()){
arry.delete();
continue;
}
if(arry.length()<40){
System.out.println("非法文件, 被删除!");
arry.delete();
continue;
}
/
把当前的文件文件流的形式打开.
/
FileInputStream inputfile=new FileInputStream(arry);
/
把文件流实例化成一个反压流.
反压流---该流的指针能随文件的读入而移动.而且能够返回以读完的流的指针向量.
/
PushbackInputStream readfile=new PushbackInputStream(inputfile,653600);
readfile.read(class_total,0,4);
int class_total_l=toInt(class_total);
if(class_total_l>10){
inputfile.close();
readfile.close();
// readfile.unread(class_total,0,4);
System.out.println("非法文件, 被删除!");
arry.delete();
continue;
}
/
用于存储数据库的链接串,分别是hostname,port,SID,username,password.
/
Class.forName("oracle.jdbc.driver.OracleDriver");
/
建立JDBC的连接.
/
Connection conn= DriverManager.getConnection ("jdbc:oracle:thin:@"+sernews.jdbcdrive,sernews.username,sernews.psw);
// Connection conn= DriverManager.getConnection ("jdbc:oracle:thin:@e5500:1521:ora815","xc","xc");
//Connection conn= DriverManager.getConnection ("jdbc:oracle:thin:@172.20.83.170:1521:ora9i","xc","xc");
conn.setAutoCommit(false);
/
JDBC声明.
/
Statement stmt = conn.createStatement();
/
JDBC返回结果集.
/
ResultSet result = stmt.executeQuery("select max(news_id) from t_news_class_1");
if(result.next()){
news_id=result.getLong(1);
news_id=news_id+1;
}
int class_id_l;
for(int j=0;j
class_id_l=toInt(class_id);
stmt.execute("insert into t_news_class_1(news_id,news_class_id) values("+news_id+","+class_id_l+")");
// stmt.execute("insert into t_news_class_1_all(news_id,news_class_id) values("+news_id+","+class_id_l+")");
}
readfile.read(news_date,0,4);
/
把字节型的日期转换成一个整形的数值.
/
int lDate_value=toInt(news_date);
readfile.read(news_time,0,4);
/
把字节型的时间转换成一个整形的数值.
/
int lTime_value=toInt(news_time);
/
把整型的日期转换成一个字符.
/
String sundate=String.valueOf(lDate_value);
/
把整型的时间转换成一个字符.
/
String suntime=String.valueOf(lTime_value);
int len=suntime.length();
if(len<6)
{
for(int j=0;j<(6-len);j++)
suntime="0"+suntime;
}