本文共 879 字,大约阅读时间需要 2 分钟。
package com.kedia.io;
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class IOTest { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { FileReader fileReader = new FileReader("C:/Users/Administrator/Desktop/20170217.sql"); BufferedReader reader = new BufferedReader(fileReader); int x = 0; String line = null; while ((line = reader.readLine()) != null) { if(line.contains("CREATE TABLE")){ x = x + 1; writerTableName(line); } } System.out.println(x); reader.close(); } public static void writerTableName(String line) throws Exception{ FileWriter fileWriter = new FileWriter("C:/Users/Administrator/Desktop/20170217.txt",true); BufferedWriter writer = new BufferedWriter(fileWriter); writer.write(line); writer.newLine(); writer.flush(); writer.close(); } }
转载地址:http://fcuhj.baihongyu.com/