반응형
1. List 형식으로 읽기
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 | public void danbiExecute() { // 데이터 가져오기 List<String> row = new ArrayList<String>(); File file = new File("D:/Keyword/description.txt"); try { System.out.println(file.getAbsoluteFile() + " reading..."); BufferedReader inFiles = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsolutePath()), "UTF8")); String line = ""; while((line = inFiles.readLine()) != null) { if(line.trim().length() > 0) { row.add(line); } } inFiles.close(); } catch (Exception e) { e.printStackTrace(); } // 데이터 출력하기 Iterator<String> iterator = row.iterator(); while(iterator.hasNext()) { // 한 개의 객체를 가져옴, 형태소 분석할 문장 String document = iterator.next(); List<String> all = extractNoun(document); System.out.println(all); all.clear(); } } } |
|
2. String 형식으로 읽기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public class maintest2 { public static void main(String[] args) { String a = ""; File file = new File("C:/Users/kej82/Desktop/학습자료/JAVA/Example/news.txt"); try { System.out.println(file.getAbsoluteFile() + " reading..."); BufferedReader inFiles = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsolutePath()), "UTF8")); String line = ""; while((line = inFiles.readLine()) != null) { if(line.trim().length() > 0) { a += line + " " ; } } inFiles.close(); } catch (Exception e) { e.printStackTrace(); } |
|
'프로그래밍 > Java' 카테고리의 다른 글
[JAVA 코드] 데이터 활용, 테이블 필드 생성 (0) | 2018.12.19 |
---|---|
[JAVA 코드] 배열 비교 (0) | 2018.12.17 |
[JAVA 이론] JDBC 프로그래밍(DB연결) (0) | 2018.12.05 |
[JAVA 이론] Map Collection (0) | 2018.11.18 |
[JAVA 이론] Set Collection (0) | 2018.11.15 |
댓글