๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿš— Major Study (Bachelor)/๐ŸŸ  JAVA Programming

JAVA ํ”„๋กœ๊ทธ๋ž˜๋ฐ 10.2

by UKHYUN22 2021. 11. 6.
728x90

 

filter class๊ฐ€ ๋ฌด์—‡์ธ์ง€์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋Š” ์‹œ๊ฐ„~

 

PrintWriter ์™€ BufferedReader ์—†์ด๋„ File I/O๋ฅผ ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ์‚ฌ์šฉ์ž๊ฐ€ ์ผ์ผ์ด Integer๋กœ Byte๋กœ ๋ฐ”๊พธ๊ณ  ์ด๋Ÿฐ ๊ณผ์ •์„ ๋‹ค ํ•ด์•ผ ํ•œ๋‹ค. ๊ทธ๊ฒƒ์„ ๋„์™€์ฃผ๋Š” ๊ธฐ๋Šฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์ด๋‹ค.

 

 

 

PrintWriter๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ณผ์ •์—์„œ FileNotFoundexception์ด ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ์œผ๋‹ˆ  ํ•ด๋‹น Constructor๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ชฝ์—์„ธ ์ด์— ๋Œ€ํ•œ ๋Œ€์ฑ…์„ ์„ธ์›Œ๋ผ!!

 

 

 

 

filter class

 

FileOutputStream, ์ƒ์–ผ์— ํ•ด๋‹นํ•˜๋Š” ๊ฒƒ์„ ๊ฐ€์ง€๊ณ  ์ž‘์—…์„ ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

PrintWriter(ํ™”์žฅํ’ˆ ์—ญํ• ) 

filter class: ์—ฌ๋Ÿฌ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ Write ํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํด๋ž˜์Šค

 

 

by the operating system, the stream name

 

File์€ 2๊ฐ€์ง€ ์ข…๋ฅ˜์˜ ํŒŒ์ผ์ด ์žˆ๋‹ค.

 

 

println์ด๋ผ๋Š” ๋ฉ”์†Œ๋“œ๋Š” FileOutputStream์— ์žˆ์ง€ ์•Š๊ณ  PrintWriter ํด๋ž˜์Šค ์•ˆ์— ์กด์žฌํ•œ๋‹ค.

 

 

 

FileOutputStream์€ OutputStream์„ Extend ํ•œ๋‹ค.

 

 

true

 

true๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ์กด์˜ ํŒŒ์ผ์„ ์—†์• ์ง€ ๋ง๊ณ  ๊ทธ ๋’ค์— ๋‹ค๊ฐ€ Append 

 

 

 

 

๋‹ซ๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

 

 

abnormally, closed

 

๋น„์ •์ƒ์ ์œผ๋กœ ์ข…๋ฃŒํ•˜์ง€ ์•Š์•˜๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ closeํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. 

Read ์šฉ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์— Write ํ•˜๊ณ  ์žˆ๋˜ ๊ฒƒ์„ close ํ•ด์•ผ ํ•œ๋‹ค.

 

 

Filter

 

oneRecord.toString(), oneRecord

 

toString()์„ ์ƒ๋žตํ•ด๋„ ๋œ๋‹ค.