자바 텍스트 파일 읽어서 DB에 insert (구분자 파이프 |)
file.my=C:\\file\\
@Value("${file.my}")
private String path;
@Scheduled(cron="${batch.time4}")
public void aBatch() throws Exception{
System.out.println("My Batch Start");
try {
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
Calendar cal=Calendar.getInstance();
cal.add(cal.DATE, -1);
String file1="";
String date=sdf.format(cal.getTime());
file1="a_"+date+".txt";
File myFile = new File(path+file1); //config.properties
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(myFile),"EUC-KR"));//문자인코딩
String line = null;
int resultCnt=0;
while ((line = reader.readLine()) != null ) {
System.out.println(line);
if(line != null){
String[] arr = line.split("-");
if(arr.length > 5){
HashMap map = new HashMap();
String empNo=arr[8];
if(empNo == null || "".equals(empNo)){
continue;
}
map.put("EMP_NO" ,empNo);
map.put("WORK_DATE" ,arr[0]);
map.put("WORK_TIME" ,arr[1]);
cDao.insertA(map);
}
}
resultCnt++;
}
} catch (Exception e) {
}
}