现在我要写一个定时程序定时读取该目录下的所有txt文件到数据库,并把这些txt文件转移到另外一个目录...

/*
* Created on 2004-9-30
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.io.*;
import java.util.*;
public class Test {
public static List getTextFile(String path){
File parentFile=new File(path);
File[] childrenFile=parentFile.listFiles();
ArrayList txtFile=new ArrayList();
if(childrenFile!=null&&childrenFile.length>0){
for(int i=0;i<childrenFile.length;i++){
if(childrenFile[i].getName().endsWith(".txt"))
txtFile.add(childrenFile[i]);
}
}
return txtFile;
}
public static void copyFile(List list,String path)throws Exception{
if(list!=null&&list.size()>0){
File mkFile=new File(path);
mkFile.mkdirs();
for(int i=0;i<list.size();i++){
File file=(File)list.get(i);
// DataInputStream in=new DataInputStream(new FileInputStream(file));
BufferedReader in=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
DataOutputStream out=new DataOutputStream(new FileOutputStream(path+"/"+file.getName()));
String s="";
while((s=in.readLine())!=""&&s!=null){
WriteToDB(s," ");
out.writeUTF(s);
}
in.close();
out.flush();
out.close();

}
}
}
public static void WriteToDB(String s,String flag){
String[] ss=s.split(flag);
if(ss.length>0&&ss!=null){
for(int i=0;i<ss.length;i++){
//写入Db
}
}
}
public static void main(String args[])throws Exception{
List list=getTextFile(args[0]);
if(list!=null&&list.size()>0){
for(int i=0;i<list.size();i++){
File file=(File)list.get(i);
System.out.println(file.getName());
}
}


copyFile(list,args[1]);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值