package com.app.count.Action; import com.app.ActionSupport.ActionSupportBase; import com.app.count.Service.inter.HunterProjectConvertDataService; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.sql.Date; import java.util.HashMap; import java.util.Map; /** * */ public class HunterProjectConvertDataImportAction { private HunterProjectConvertDataService hunterProjectConvertDataService; public void readFileByLines() { File file = new File("D:\\hunterdata\\******"); BufferedReader reader = null; try { // System.out.println("以行为单位读取文件内容,一次读一整行:"); reader = new BufferedReader(new FileReader(file)); String tempString = null; int line = 1; // 一次读入一行,直到读入null为文件结束 while ((tempString = reader.readLine()) != null) { // 显示行号 // System.out.println("line " + line + ": " + tempString); String[] str = tempString.split("@@"); if (!str[0].equals("CONCAT(offer_id,'")){ SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); Date date1=new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date1); calendar.add(Calendar.DAY_OF_MONTH, -1); date1 = calendar.getTime(); String date = sdf.format(date1); String offer_id = str[0]; String country = str[1]; String pkg = str[2]; String count = str[3]; String payout = str[4]; String project = str[5]; String partner = str[6]; Map<String, Object> map=new HashMap<String, Object>(); map.put("date",date1); map.put("offerId",Integer.valueOf(offer_id.toString())); map.put("country",country); map.put("pkg",pkg); map.put("count",Integer.valueOf(count.toString())); map.put("payout",payout); map.put("project",project); map.put("partner",partner); hunterProjectConvertDataService.insertHunterProjectConvertData(map); line++; } } reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } } public void setHunterProjectConvertDataService(HunterProjectConvertDataService hunterProjectConvertDataService) { this.hunterProjectConvertDataService = hunterProjectConvertDataService; } }
转载于:https://my.oschina.net/u/3426737/blog/1579201