日期:2014-05-16 浏览次数:20908 次
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class SQLparser { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { if (args == null || args.length != 1) { System.out.println("error on args"); return; } File file = new File(args[0]); if (!file.isFile()) { System.out.println("error arg[0] not a file"); return; } System.out.println(file.getName() + "BEGIN!"); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(new File("d:\\parsed.sql")), "utf-8")); BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(file), "utf-8"/* 指定源文件的字符集编码 */)); String line = br.readLine(); while (line != null) { if (line.contains(", c_dzd.voucher='"/* 匹配需要留下的SQL片段 */)) { System.out.println(line); bw.append(line + ";\n"/* 追加分号和换行 */); } line = br.readLine(); } br.close(); bw.close(); System.out.println(file.getName() + "OK!"); } }