// 파일안에 문장을 읽어서 특정단어 서치
import java.io.*;
import java.util.*;
public class FindWordWriteFile {
public static void main( String[] args ) {
try {
// 파일에서 데이타를 읽이 위한 FileReader 객체 생성
FileReader fr = new FileReader( "input.txt" );
// 버퍼에 임시 저장한 후에 데이타를 읽어 오기 위한,
// BuffreredReader 객체 생성
BufferedReader br = new BufferedReader( fr ); //입력버퍼 추가!!!
// 원하는 파일에 데이타를 전송하기 위한,
// FileWriter 객체 생성
FileWriter fw = new FileWriter( "output.txt" ); //기존 파일 삭제하고 생성 + 결국 출력되는대상
// 임시 저장 장소인 버퍼에 데이타를 모았다가,
// 출력 시켜 주기 위한 BufferedWriter 객체 생성
BufferedWriter bw = new BufferedWriter( fw ); //출력버퍼 생성!!!
// 라인수를 출력 하기 위한 변수
int count = 1;
// 파일에서 데이타를 한 줄 읽어 들임
String line = br.readLine();
// 파일의 데이타를 모두 읽을 때까지
while( line != null ) {
// 공백을 기준으로 문자열을 구분
StringTokenizer st = new StringTokenizer( line, " " );
// StringTokenizer => (" ") 단위로 끊는다.
while( st.hasMoreTokens() ) {
// (" ")가 생길때마다 true값 리턴 <= hasMoreTokens()
// + false 이면 아래 내용실행
// + false 이면 아래 내용실행
// 끊어서 읽은 내용은 별도의 string에 저장
// "String"단어와 일치하면
if( st.nextToken().equals( "String" )) {
// 화면에 결과 값을 출력
String result = count + " Line : " + line.trim();
System.out.println( result );
// 파일에 결과를 저장
bw.write( result );
// 현재 버퍼에 저장된 내용을 출력 스트림을
// 통해 전송 시킨다.
bw.flush(); //출력버퍼내용을 모두 옮기고 삭제
// 새로운 라인으로 이동
bw.newLine();
break;
}
}
// 다음 라인을 읽어 들임
line = br.readLine();
// 라인수를 증가
count++;
}
} catch ( Exception e ) {
System.out.println( e.toString() );
}
}
}
- Open in Google Docs Viewer
- Open link in new tab
- Open link in new window
- Open link in new incognito window
- Download file
- Copy link address
- Edit PDF File on PDFescape.com
- Open in Google Docs Viewer
- Open link in new tab
- Open link in new window
- Open link in new incognito window
- Download file
- Copy link address
- Edit PDF File on PDFescape.com
element
| Font | |
|---|---|
| font-family | |
| font-size | |
| font-style | |
| font-variant | |
| font-weight | |
| letter-spacing | |
| line-height | |
| text-decoration | |
| text-align | |
| text-indent | |
| text-transform | |
| white-space | |
| word-spacing | |
| color | |
| Background | |
| bg-attachment | |
| bg-color | |
| bg-image | |
| bg-position | |
| bg-repeat | |
| Box | |
| width | |
| height | |
| border-top | |
| border-right | |
| border-bottom | |
| border-left | |
| margin | |
| padding | |
| max-height | |
| min-height | |
| max-width | |
| min-width | |
| outline-color | |
| outline-style | |
| outline-width | |
| Positioning | |
| position | |
| top | |
| bottom | |
| right | |
| left | |
| float | |
| display | |
| clear | |
| z-index | |
| List | |
| list-style-image | |
| list-style-type | |
| list-style-position | |
| Table | |
| vertical-align | |
| border-collapse | |
| border-spacing | |
| caption-side | |
| empty-cells | |
| table-layout | |
| Effects | |
| text-shadow | |
| -webkit-box-shadow | |
| border-radius | |
| Other | |
| overflow | |
| cursor | |
| visibility |
element
| Font | |
|---|---|
| font-family | |
| font-size | |
| font-style | |
| font-variant | |
| font-weight | |
| letter-spacing | |
| line-height | |
| text-decoration | |
| text-align | |
| text-indent | |
| text-transform | |
| white-space | |
| word-spacing | |
| color | |
| Background | |
| bg-attachment | |
| bg-color | |
| bg-image | |
| bg-position | |
| bg-repeat | |
| Box | |
| width | |
| height | |
| border-top | |
| border-right | |
| border-bottom | |
| border-left | |
| margin | |
| padding | |
| max-height | |
| min-height | |
| max-width | |
| min-width | |
| outline-color | |
| outline-style | |
| outline-width | |
| Positioning | |
| position | |
| top | |
| bottom | |
| right | |
| left | |
| float | |
| display | |
| clear | |
| z-index | |
| List | |
| list-style-image | |
| list-style-type | |
| list-style-position | |
| Table | |
| vertical-align | |
| border-collapse | |
| border-spacing | |
| caption-side | |
| empty-cells | |
| table-layout | |
| Effects | |
| text-shadow | |
| -webkit-box-shadow | |
| border-radius | |
| Other | |
| overflow | |
| cursor | |
| visibility |
