필요지식 : java io , 정규식작성방법
Am, Ap, Ex, Mo, Sy 외 같은 단어라서 배열에 해당 단어만 넣어주고 다른건 문자로 취급한다.
추출할 문자 규칙은 TB_ 로 시작하는 문자라서,
정규식을 (?=TB_.)+[A-z]\w* 로 작성하였다.
후자도 TB_ 앞에 공백(띄어쓰기, 엔터, 탭 등 한 번은 ) 이 포함된다
(?=TB_.)+[A-z]\w* 설명
(?=TB_.) = 후방검색 , TB_ 이후 모든 글자 검색 [A-z]\w* = [A-z] , A부터 z까지 검색 (대소문자 포함검색) \w , 알파벳이나 문자 (특수문자 [ 괄호 등 ] 제외 ) * or + , *-> 0개이상, + -> 1개이상 매칭
|
전에 작성한 정규식 관련 지식 | https://404008.tistory.com/65 |
정규식으로 파싱한 값을 따로 저장하였다.
[순서] 테이블명
중복체크없이 뽑음
전체소스
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
package java_01;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class two {
public static void main(String[] args) throws Exception {
SimpleDateFormat format_form = new SimpleDateFormat ( "yyyy년 MM월dd일 HH시mm분ss초");
Date time = new Date();
String[] Mapper_name = { "Am" , "Ap" , "Ex", "Mo", "Sy"};
String Mapper_add = "C:\\OutputStream_C\\input_test\\bd"; // 읽을 xml 파일
String str_tb = "(?=TB_.)+[A-z]\\w*"; // 찾을 문자 정규식
String Mapper_total =""; // 찾을 매핑 이름
String save_name =""; // 저장명
OutputStream output = null;
BufferedReader fileReader = null ;
boolean found_tf = true; // while 문 컨트롤
int cnt = 1; // 저장시 개수 카운트
String str = ""; // 저장 String
byte[] str_bytes ; // 저장시 String -> byte로 변환
String line = "";
Pattern p ;
Matcher m ;
for ( String M_name : Mapper_name ) {
save_name = "C://OutputStream_C/" + M_name +"_"+ format_form.format(time) + ".txt"; // 저장명
output = new FileOutputStream(save_name); // 찾은 내용만 저장
fileReader = new BufferedReader(new FileReader(Mapper_total)); // 읽을 xml파일 bufferReader로 읽기
line = fileReader.readLine(); // xml 파일의 첫 줄 읽기
System.out.println("Mapper_total >> " + Mapper_total); // 읽을 위치
System.out.println("save_name >> " + save_name); // 저장위치
while (found_tf) {
line = fileReader.readLine(); // 첫 줄 이후 읽기
if(line==null) {
System.out.println(Mapper_total + " [ End ]\n"); // 끝난거 알려줌
found_tf = false;
}
else {
p = Pattern.compile(str_tb);
m = p.matcher(line);
if(m.find()) {
str = "["+ cnt++ +"]\t" + m.group() +"\n";
str_bytes = str.getBytes();
}
}
}
found_tf = true; // 다른 배열 while문 돌게 변경
cnt=1;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
추가로 보면 좋을 책
자바설치 오류 ')'가 필요합니다. (1) | 2021.06.02 |
---|---|
[JAVA] 이클립스'Could not create the Java Virtual Machine''A fatal exception has occurred. Program will exit.' 시작 오류 해결 (0) | 2020.04.22 |
war / (0) | 2020.04.20 |
[Java] 정규식 표현 (Regular Expression) (0) | 2020.04.20 |
개인 프로젝트 2020.03.25-2020.04.13. (3) | 2020.04.20 |
댓글 영역