티스토리 뷰
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 | package test2; import java.io.File; public class Drectory { public static void main(String [] args){ String path="D:\\data\\"; System.out.println("----- drectory Test -----"); drectoryTree(path); } public static void drectoryTree(String path){ //System.out.println("------> path =" + path ); File file= new File(path); String result=""; File temp[] = file.listFiles(); if(temp.length>0){ for(int i =0; i<temp.length; i++){ System.out.println("--------> "+temp[i]); if(temp[i].isDirectory()){ result=path; drectoryTree(temp[i].toString()); }else{ result=temp[i].getName(); } } } } } |
-------------- 실행 결과 -------------------
----- drectory Test -----
--------> D:\data\service
--------> D:\data\service\B2CAdmin
--------> D:\data\service\B2CAdmin\ddd
--------> D:\data\service\B2CAdmin\ddd\test.txt
--------> D:\data\service\B2CAdmin\images
--------> D:\data\service\B2CAdmin\images\main
--------> D:\data\service\B2CAdmin\images\main\issue_10.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_11.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_12.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_14.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_15.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_16.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_17.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_18.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_20.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_28.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_29.JPG
--------> D:\data\service\B2CAdmin\images\main\issue_30.JPG
몇번에 실패를 거듭했다가 ㅡㅡ 우연하게 했더니 됨..
------------------------------------------------------------------------------------------
응용 편
------------------------------------------------------------------------------------------
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 | package test2; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; public class Drectory { public static void main(String [] args){ //String path="Y:\\Inbound"; String path="Y:\\test"; System.out.println("----- drectory Start -----"); drectoryTree(path); System.out.println("----- drectory End -----"); } public static void drectoryTree(String path){ //System.out.println("------> path =" + path ); File file= new File(path); String result=""; File temp[] = file.listFiles(); try{ if(temp.length>0){ for(int i =0; i<temp.length; i++){ //System.out.println("--------> "+temp[i]); if(temp[i].isDirectory()){ result=path; drectoryTree(temp[i].toString()); }else{ result=temp[i].getName(); if(result.indexOf("01.html")>0){ System.out.println("--------->"+temp[i].toString()); getHtmlParsing(temp[i].toString()); } } } } }catch(Exception e){ e.printStackTrace(); } } public static void getHtmlParsing(String path) throws IOException{ FileReader fileReader = null; BufferedReader bufReader = null; OutputStreamWriter ot = null; try { fileReader = new FileReader(path); bufReader = new BufferedReader(fileReader); StringBuffer str = new StringBuffer(); String line = null; while((line = bufReader.readLine()) != null ) { //line=line.replace("<head>", "<head> \n<script type='text/javascript'>var a1 =1; var b=2;</script>"); line=line.replace("<script type='text/javascript'>var a1 =1; var b=2;</script>", ""); str.append(line).append("\n"); } bufReader.close(); fileReader.close(); ot = new FileWriter(path); ot.write(str.toString()); ot.flush(); System.out.println(str.toString()); } finally { if (bufReader != null) bufReader.close(); if (fileReader != null) fileReader.close(); } } } |
디렉토리를 따라서 이동하다가 원하는 html파일을 찾고 난 뒤에
내용일 읽어서 <head> 부분에 스크립트를 리플레이스 해준다!
이것임.
- Total
- Today
- Yesterday
- Database#transaction
- java 압축 풀기
- java 특정문자 갯수구하기
- jstl foreach
- jstl 커스텀 태그
- POE Excel 만들기
- spring property
- spring ExcelView
- 코루틴
- MyBatis 팁
- github image 첨부시 주의할점
- coroutine
- JSP 세션
- jstl split
- 전자정부프레임워크 tiles
- java 설정
- java 설치
- POI EXCEL
- java calendar
- JSTL
- java 폴더구조 구하기
- mybatis Merge
- Kotlin
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |