import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author yg
* */
public class TxtUtils {
/**
* 按行提取文本
* @param file
* @return List<String>
*/
public static List<String> extractTXTbyLine(String file) {
List<String> listArr = new ArrayList<String>();
try {
FileInputStream fin = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(fin);
BufferedReader buffReader = new BufferedReader(reader);
String strTmp = "";
while((strTmp = buffReader.readLine())!=null){
listArr.add(strTmp);
}
} catch (IOException ex) {
Logger.getLogger(TxtUtils.class.getName()).log(Level.SEVERE, null, ex);
}
return listArr;
}
public static void main(String args[]) {
String savePath = "F:\\文档\\result2.txt";
long startTime = System.currentTimeMillis();
List<String> strings = extractTXTbyLine(savePath);
for (String s : strings) {
System.out.println(s);
}
long endTime = System.currentTimeMillis();
System.out.println("读写所用时间为:" + (endTime - startTime) + "ms");
}
}