반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

java.BufferedReader 본문

[IT]/java

java.BufferedReader

givemebro 2021. 3. 15. 10:53
반응형

package step1;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class TestInput1 {
	public static void main(String[] args) {
		String path = "C:\\4. kosta215\\iotest\\friend.txt";
		// System.out.println(new File(path).isFile());
		try {
			// 입력받는 노드 문자스트림 : FileReater
			FileReader fr = new FileReader(path);
			// 입력 프로세스 문자스트림 : BufferedReader
			BufferedReader br = new BufferedReader(fr);
			// System.out.println(br.readLine());
			// System.out.println(br.readLine());
			// System.out.println(br.readLine());
			// System.out.println(br.readLine());// 더 이상 읽을 문자열 라인이 없으면 null 반환
			String s = "";
			while (s != null) {
				s = br.readLine();
				System.out.println(s);

			}
			br.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

package step1;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

// TestInput1의 입력 방식을 다른 방법으로 해본다( ready()를 이용)
public class TestInput2 {
	public static void main(String[] args) {
		String path = "C:\\4. kosta215\\iotest\\friend.txt";
		// System.out.println(new File(path).isFile());
		try {
			// 입력받는 노드 문자스트림 : FileReater
			FileReader fr = new FileReader(path);
			// 입력 프로세스 문자스트림 : BufferedReader
			BufferedReader br = new BufferedReader(fr);
			// System.out.println(br.readLine());
			// System.out.println(br.readLine());
			// System.out.println(br.readLine());
			// System.out.println(br.readLine());// 더 이상 읽을 문자열 라인이 없으면 null 반환

			while (br.ready()) {// 문자열이 있으면 true
				System.out.println(br.readLine());
			}
			br.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
반응형

'[IT] > java' 카테고리의 다른 글

java.SerialVersionUID  (0) 2021.03.15
java.byte파일 컨트롤  (0) 2021.03.15
java.문자열 파일 컨트롤  (0) 2021.03.15
java.file입력/출력  (0) 2021.03.15
java.Scanner(입력)  (0) 2021.03.12
java.Stream.NodeStream/ProcessingStream  (0) 2021.03.12
java.IO.File/Directory  (0) 2021.03.12
java.switch  (0) 2021.03.11
Comments