package com.ynu.www.tool;
import java.io.*;
import java.util.*;
//流的关闭顺序:先打开的后关,后打开的先关,否则有可能出现java.io.IOException: Stream closed异常
//读取txt文档中的内容,写入数据库。
public class Txt2Database {
private final static String PATH = System.getProperty("user.dir");
public final static String DIR = PATH + "/src/com/ynu/www/data/";
public List<List> readeTxt(String filename) {
// 用于存放txt文件里所有的数据
List txtList = new ArrayList<List>();
try {
// 用来记录读到第几行记录
int id = 0;
FileReader fr = new FileReader(DIR + filename);
BufferedReader bf = new BufferedReader(fr);
String str = null;
while ((str = bf.readLine()) != null) {
// 用于存放txt文件里每行数据
List tempList = new ArrayList<Integer>();
id++;
String[] strs = str.split(" ");
if (strs[0] != null && !strs[0].equals("") && strs[1] != null
&& !strs[1].equals("")) {
tempList.add(Integer.parseInt(strs[0]));
tempList.add(Integer.parseInt(strs[1]));
} else {
System.out.println("读取第" + id + "行