-> System.in.read()
-> println(String str)
-> print(String str)
-> write(int b)
-> flush() // write 와 짝꿍, auto 로도 가능!
- (윈도우)Ctrl+Z , (유닉스,리눅스,맥) Ctrl+D 라면 ' -1 ' 을 반환
-> ' -1 ' 은 데이터 입력의 끝을 의미한다.
- 'Enter' 는 \r\n
-> \r (carriage return) 은 ' 13 ' 을 반환
-> \n (new line) 은 ' 10 ' 을 반환
인코딩 설정
한글 1자 => 2byte
영어 1자 => 1byte
int input = 0;
int totalByte = 0;
while(true) {
input = System.in.read(); // 1byte 씩 읽기
if(input != 13 && input != 10) // Enter가 아니면
if((char)input == 'x' || (char)input == 'X') {
// X 이면
break;
}
System.out.println("글자 1개씩(char)만 읽어들여 "
"char 에 해당하는 int 타입으로 반환한 값 : " + input);
// ex) input 이 a라면, ' 97 '
totalByte++;
===== 방법 1 =====
/*
System.out.println
("화면에 출력 [println 사용한 input] : " + (char)input);
// (char)input 은 입력한 값
*/
===== 방법 2 =====
/*
System.out.print
("화면에 출력 [write 사용한 input] : ");
System.out.write(input); // 입력한 값 1byte 씩 쓰기
System.out.flush(); // 입력한 값 1byte 씩 내뿜기
*/
} else { // Enter 를 입력하였다면
System.out.println("");
} // end of if~else-------------
} // end of while(true)-------------------------
System.out.println
(">> 입력받은 byte 수 : " + totalByte + "byte");
byte [] data_arr = new byte[숫자];
// 이때 숫자는 몇 byte 마다 끊을지 적는 것이다.
int input_length = 0; // 한번 읽을 때의 길이
int totalByte= 0; // byte 수 누적 용도
int cnt = 0; // 몇 번 반복하는지 확인 용도
while((input_length = System.in.read(data_arr)) != -1) {
// 입력한 값이 데이터 입력의 끝을 의미하는 것이 아니면
System.out.write(data_arr,0,input_length);
// write(저장된 장소, 배열의 출발점, 읽어올 길이)
// 0번 index 부터 input_length byte 수 만큼 작성
System.out,flush(); // 작성한 만큼 내뿜기
totalByte += input_length;
cnt++;
} // end of while--------------------------------------
System.out.println("총 : " + (totalByte-2 + "byte 입력함");
// Enter 의 byte : 2 byte
System.out.println("반복횟수 : " + cnt + "번 반복함");
C:\Users\users>cd C:주소~~~\bin
C:\NCS\workspace_java\Begin\bin>java 패키지명.클래스명
my.day20.a.io
-> Stream 구분, InputStream_main_01, InputStream_main_02, InputStream_main_02을명령프롬프트에서실행한화면, InputStream_main_03, InputStream_main_04