일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- https://hi-zini.tistory.com/entry/%EB%B9%84%EB%8F%99%EA%B8%B0%EC%A0%81-%EB%B0%A9%EC%8B%9D-%EC%B2%98%EB%A6%AC-%EB%B0%A9%EB%B2%95-Callback-Promise-async-await
- https://appmaster.io/ko/blog/rest-apiran-mueosimyeo-dareun-yuhyeonggwa-eoddeohge-dareungayo
- https://sewonzzang.tistory.com/22
- https://joshua1988.github.io/web-development/javascript/js-async-await/
- https://siyoon210.tistory.com/130
- https://aws.amazon.com/ko/docker/
- https://subicura.com/2017/01/19/docker-guide-for-beginners-1.html
- https://goodgid.github.io/HTTP-Communicate-Process/
- https://jcon.tistory.com/189
- https://joshua1988.github.io/web-development/javascript/promise-for-beginners/
- Today
- Total
“Connecting the dots”
Java Study 파일을 읽어와서 내용을 콘솔에 출력하는 코드 본문
package exif;
import java.io.FileReader;
import java.io.IOException;
public class _02_Exwhile2_파일읽기 {
public static void main(String[] args) throws Exception {
//파일 읽기 객체
FileReader fr = new FileReader("a.txt");
FileReader 클래스를 사용하여 "a.txt" 파일을 열어서 파일 읽기 객체 'fr'을생성
int count = 0;
while(true)
{
int ch = fr.read(); //문자 1개읽어오가ㅣ
//화일의 끝(EOF:-1)이면 while문 탈출해
if(ch==-1)break;
count++;
System.out.printf("%c", ch);
}
While 반복문을 사용하여 파일의 끝까지 한 문자씩 읽어들입니다
int ch =fr.read();
fileReader 객체의 read()메소드를 사용하여 한 문자를 읽어 옵니다 읽어드린 문자느 int 형으로 반환합니다
if(ch== -1) break :파일의 끝을 나타내는 EOF(-1)dls ruddn break 문을 사용하여 while문을 탈출합니다
count++ :한 문자를 읽을 때마다 count 변수를 1씩 증가시킵니다
System.out.printf("%c", ch): 읽어들인 문자를 콘솔에 출력
read 메소드를 이용하여 파일을 읽어 옵니다
System.out.printf("\n반복횟수:%d(회)n",count);
//닫기
fr.close();
fileReader 객체를 닫습니다
}
}
'JAVA' 카테고리의 다른 글
java study (0) | 2023.04.10 |
---|---|
JAVA Study 자바로 구현된 구구단 프로그램구현. (0) | 2023.04.07 |
JAVA STUDY 제어문 (0) | 2023.04.05 |
JAVASTUDY 10진수를 2진수로 변환하여 출력하는 기능 (0) | 2023.04.05 |
java if문 (0) | 2023.04.04 |