日期:2014-05-20 浏览次数:21073 次
List<Integer> targetLine = Arrays.asList(new Integer[]{2, 4, 5, 6});
int currentLine = 0;
List<String> data = new ArrayList<String>();
Scanner sc = new Scanner(new FileInputStream("yourfile"));
while (sc.hashNextLine()) {
String s = sc.nextLine();
currentLine++;
if (targetLine.contains(currentLine)) data.add(s);
if (currentLine > targetLine.get(targetLine.size()-1)) break;
}
sc.close();
String sql = "insert xxx values(?, ?, ?, ?);"
PreparedStatement ps = yourConnection.prepareStatement(sql);
for (int i=0; i<data.size(); i++) {
ps.setString(i+1, data.get(i));
}
ps.executeUpdate();