Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- java#왕초보
- webpack
- 오버라이드
- 코틀린
- 스타일보험
- 시큐어코딩
- 안드로이드
- 쿠키
- SQL
- 왕초보
- Spinner
- parcel
- kotlin
- 스프링
- 숫자
- 답글
- Spring
- sub query
- FIle
- 버전일치
- git
- 게시판
- java
- 함수
- snowpack
- React
- degit
- 상속
- Android
- 미니게임
Archives
- Today
- Total
YSHUSH
File reader 본문
File file = new File("d:\\myfile\\newfile.txt");
FileReader fr;
// 파일 읽기
try {
// 한글자씩 읽기
/*
fr = new FileReader(file);
int ch = fr.read();
while(ch != -1) { // 한글자씩 읽었다가 [(-1) = 데이터가 없을때까지] 읽어라
System.out.println((char)ch);
ch = fr.read();
}
fr.close();
*/
// 문장으로 읽기
/*
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String str;
while((str = br.readLine()) != null) {
System.out.println(str);
}
br.close();
fr.close();
*/
//원래는 위와 같이 써야하지만 밑에처럼 간소화됨
BufferedReader br = new BufferedReader(new FileReader(file));
String str;
while((str = br.readLine()) != null) { // 파일에 빈문장이 없을때까지 읽어들여!
System.out.println(str);
}
br.close(); // 읽어준다음에는 원래 닫아줘야됨
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
'Coding > Java' 카테고리의 다른 글
OOP(Object Oriented Programing) (0) | 2021.12.14 |
---|---|
File writer (0) | 2021.12.14 |
File I/O (0) | 2021.12.14 |
Exception (0) | 2021.12.14 |
Overload (0) | 2021.12.14 |