您的位置:首页 > 数据库

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

2014-01-10 21:13 781 查看
/*  

    *   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]);  

          }  

  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐