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].getPath().endsWith(".txt"))
                    txtFile.add(childrenFile[i]);                
            }
        }
        return txtFile;
       }    
不好意思,马上下班了,没时间了。就写了这个读txt的。
定时那个可以用线程,也可以写个bat文件,在计划任务里面加上定时执行这个bat。

解决方案 »

  1.   

    /*
     * 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]);
        }
    }
    初学,见笑了。
      

  2.   

    //处理文件内容
    public String [] getFileContent ()
    {
            String [] strContent = new String [10];
            String strTmp = null;
            String strPath = null;        //strPath = ClassLoader.getSystemResource ("test/test.txt").toString().substring(6);
            BufferedReader bf = null;        try
            {
                    bf = new BufferedReader (new FileReader ("D:/test.txt"));
                    while (bf.ready ())
                    {
                            strTmp = bf.readLine();
                            strContent = strTmp.split("   ");
                            //System.out.println (strTmp);
                            for (int i = 0; i < strContent.length; i ++)
                            {
                                    System.out.print (strContent [i] + ",");
                            }
                            System.out.println ("");
                    }
            }
            catch (Exception e)
            {
                    System.out.println (e.toString ());
            }        return (strContent);
    }
      

  3.   

    给个思路:
    1.把每个txt文件导入Oracle可通过Oracle自带的imp程序导入,自己写个类似
    Load data 
    infile 'data\customer0401.txt'
    append
    into table tblCustomer
    fields terminated by  ' '
    trailing nullcols
    (
        SERIES_ID ,
        Cust_id,
        category_flag,
        INITIALS, 
        sex_code,
        Title,
        cust_mp,
        cust_ph1,
        cust_fax,
        CONCAT_ADDR            "substr(trim(:concat_addr),1,64)",
        cust_email,
        cust_postcode,
        mhi,
        Original_date Date "YYYY-MM-DD HH24:Mi:SS",
        dlr_salecode,
        veh_model,
        veh_series_model,
        Refresh_date Date "YYYY-MM-DD HH24:Mi:SS",
        status_flag,
        Agent_id
    )
    的导入文件
    2.写个批处理文件(java load 注:load为你的java程序)读取当前目录下所有的txt文件,对每个文件运行imp导入
    3.在windows的计划调度中加入这个批处理,自己设置调度时间
      

  4.   

    更正2:批处理内容为:
    sqlldr crc1dev@user/password control=xxx.ctl