读取磁盘上文件夹的名字的一个应用

package com.tower.bgp.antTools.dirToSql;

 

import java.io.File;

import java.io.PrintWriter;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

 

import org.apache.tools.ant.BuildException;

import org.apache.tools.ant.taskdefs.MatchingTask;

 

/**

 * The purpose of this Ant Task is to allow you to use

 * Velocity create HTML.

 * @version $Id: CreateUpdSqlTask.java 524478 2007-03-31 20:51:49Z wglass $

 */

public class CreateUpdSqlsoftMain extends MatchingTask {

/**

* @param args

*/

public static void main(String[] args) {

     PrintWriter mywriter = null;

        try {

            //���·��

            String outpath = "F:\\bgp\\testsql\\software.sql";

            //���

            mywriter = new PrintWriter( outpath, "UTF-8");

         File RootDir = new File("F:\\bgp\\software");

         File[] dirs = RootDir.listFiles();

         DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

            for (File newsDir : dirs) {

             if (newsDir.isDirectory()) {

//             String tmpPath = "";

             String oldPath = "softwareUpload/";

                 String id = newsDir.getName();

             File[] files = newsDir.listFiles();

                    for (File newsFile : files) {

                     String[] filenames = newsFile.getName().split("_");

                     String filename = filenames[0];

                 String createDate = format.format(new Date(newsFile.lastModified()));

                 System.out.println("createDate = " + createDate);

                     String tmpPath = oldPath+newsDir.getName() + "/" + newsFile.getName();      

                     String sql = "insert into bgp_softview (" +

                     "sortid" +

                     ",title" +

                     ",master" +

                     ",content" +

                     ",click" +

                     ",isornot" +

                     ",createdate" +

                     ",url" +

                     ") values ( " +

                     "'" + id + "'" +

                     ",'" + filename + "'" +

                     ",'webmaster'" +

                        ",'" + filename + "'" +

                     ",null" +

                     ",null" +

                     ",'" + createDate + "'" +

                     ",'" + tmpPath + "');";

                        System.out.println("sql = " + sql);

                     mywriter.println(sql);

                    }

             }

         }

            mywriter.flush();

        }  catch (Exception e)  { 

         e.printStackTrace();

            throw new BuildException(e.getMessage(), e.getCause());

        } finally {

         if (mywriter != null) {

                mywriter.close();      

         }

        }

}

}


你可能感兴趣的:(java,apache,sql,ant,velocity)