package com.csii.pweb.query.action;

 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;

 public class JavaFile {
     public static void main(String[] args) {
         try {
             // read file content from file
             StringBuffer sb= new StringBuffer("");

             FileReader reader = new FileReader("D:/t/workflow.sql");
             BufferedReader br = new BufferedReader(reader);

             String str = null;
             final String markStart = "CREATE TABLE";
             List<String> tableNames = new ArrayList<String>();
             while((str = br.readLine()) != null) {
                 str = str.toUpperCase().trim(); //转为大写并去除两端空格
                 if(str.startsWith(markStart) && !str.startsWith("--")) {    //非注释之建表语句
                     str = str.substring(markStart.length()).replace('(', ' ');    //取表名
                     tableNames.add("DROP TABLE " + str.trim()+";");
 //                    System.out.println(str);
                 }
             }

             br.close();
             reader.close();
             //倒序
             for(int i=tableNames.size()-1; i>=0;i--) {
                 String name = tableNames.get(i);
                 sb.append(name).append("\n");
             }
             System.out.println("--------------start---------------");
             System.out.println(sb);
             System.out.println("--------------end---------------"+tableNames.size());

             // write string to file
 //            FileWriter writer = new FileWriter("c://test2.txt");
 //            BufferedWriter bw = new BufferedWriter(writer);
 //            bw.write(sb.toString());
 //
 //            bw.close();
 //            writer.close();
         }
         catch(FileNotFoundException e) {
             e.printStackTrace();
         }
         catch(IOException e) {
             e.printStackTrace();
         }
     }
 }
05-11 13:23