Android > Android - ½ºÆ®¸²(stream) - ¹®ÀÚ Stream µî·ÏÀÏ : 2017-07-05 11:01 Á¶È¸¼ö : 53,130¹®ÀÚ StreamÀº 16ºñÆ® ¹®ÀÚ³ª ¹®ÀÚ¿µéÀ» ÀÐ°í ¾²±â À§ÇÑ ½ºÆ®¸²ÀÌ°í ¸ðµÎ Reader / WriterÀÇ ÇÏÀ§ Ŭ·¡½ºÀÌ´Ù. ¹®ÀÚ ÀÔÃâ·Â ½ºÆ®¸²Àº ¿µ¾î ÀÌ¿ÜÀÇ ¹®ÀÚ¿¡ ´ëÇÑ Ã³¸®¿Í ¹®ÀÚ ÀÎÄÚµùÀ» ³»ºÎ¿¡¼ ó¸®ÇØ ÁÖ°í, À¯´ÏÄڵ带 Áö¿øÇÏ´Â Àڹ٠Ư¼º¿¡ ¸Â°Ô 2¹ÙÀÌÆ® Å©±âÀÇ ÀÔÃâ·ÂÀ» ÇÑ´Ù. µû¶ó¼ ¹®ÀÚ ½ºÆ®¸²À» ÀÌ¿ëÇÏ°Ô µÇ¸é Ưº°ÇÑ ¹®ÀÚ ÀÎÄÚµù¿¡ µ¶¸³ÀûÀÎ ÇÁ·Î±×·¥À» ÀÛ¼ºÇÒ ¼ö ÀÖ°í ÀϹÝÀûÀ¸·Î ±¸Çö¿¡¼µµ ´õ È¿À²ÀûÀÏ ¼ö ÀÖ´Ù. Reader / Writer ´Â ¹®ÀÚ ÀÔÃâ·ÂÀ» ´ã´çÇÏ´Â Ãß»ó Ŭ·¡½º·Î ´Ù¸¥ ¹®ÀÚ ÀÔÃâ·Â Ŭ·¡½ºµé¿¡ ´ëÇÑ ÃÖ»óÀ§ Ŭ·¡½ºÀÌ´Ù. Byte StreamÀÇ ÃÖ»óÀ§ Ŭ·¡½º·Î InputStream / OutputStream Ŭ·¡½º°¡ ÀÖµíÀÌ Character ´ÜÀ§ÀÇ ÀÔÃâ·ÂÀ» ´ã´çÇÏ´Â ÃÖ»óÀ§ Ŭ·¡½º·Î´Â Reader / Writer Ŭ·¡½º°¡ ÀÖ´Ù. [JAVA] ByteStream : InputStream / OutputStream ÀÌ µÎ Ŭ·¡½ºµµ Ãß»ó Ŭ·¡½ºÀ̱⠶§¹®¿¡ ½ÇÁ¦ °´Ã¼¸¦ »ý¼ºÇÒ ¼ö´Â ¾ø´Ù. ¨ç Reader Reader Ŭ·¡½º´Â Character ´ÜÀ§ÀÇ ÀÔ·ÂÀ» ´ëÇ¥ÇÏ´Â ÃÖ»óÀ§ Ãß»ó Ŭ·¡½ºÀÌ´Ù. µû¶ó¼ °´Ã¼¸¦ Á÷Á¢ »ý¼ºÇÒ ¼ö ¾øÀ¸¸ç ÈÄ¼Õ °´Ã¼¸¦ °¡¸®Å°´Â ·¹ÆÛ·±½ºÀÇ ÇüÅ·Π»ç¿ëµÈ´Ù. ±×¸®°í ÀÌ Å¬·¡½º¿¡ Á¸ÀçÇÏ´Â ¸Þ¼Òµå´Â ÈÄ¼Õ °´Ã¼¿¡°Ô »ó¼ÓµÇ°Å³ª ÀçÁ¤ÀÇµÇ¾î »ç¿ëµÈ´Ù. µ¥ÀÌÅ͸¦ Àбâ À§ÇÑ ¸Þ¼ÒµåÀÎ read() ¸Þ¼Òµå°¡ °¡Àå Áß¿äÇÑ Àǹ̸¦ °¡Áö¸ç ¹ÙÀÌÆ® ´ÜÀ§°¡ ¾Æ´Ñ char ´ÜÀ§·Î ÀԷµȴٴ °Í¸¸ ÁÖÀÇÇÏ¸é µÈ´Ù. * Reader Ŭ·¡½ºÀÇ ¸Þ¼Òµå abstract void close() throws IOException ¹®ÀÚ ÀÔ·Â ½ºÆ®¸²À» ´Ý´Â´Ù. void mark(int limit) throws IOException ¹®ÀÚ ÀÔ·Â ½ºÆ®¸²ÀÇ ÇöÀç À§Ä¡¸¦ Ç¥½ÃÇÑ´Ù. boolean markSupported() ¹®ÀÚ ½ºÆ®¸²ÀÌ mark() ¸Þ¼Òµå°¡ ÁöÁ¤µÇ¾î ÀÖ´ÂÁö ¿©ºÎ¸¦ ¹ÝȯÇÑ´Ù. int read() throws IOException ¹®ÀÚ ÀÔ·Â ½ºÆ®¸²¿¡¼ ´ÜÀÏ ¹®ÀÚ¸¦ Àд´Ù. int read(char buf[]) throws IOException ¹®ÀÚ ÀÔ·Â ½ºÆ®¸²¿¡¼ buf[] Å©±â¸¸ÅÀ» Àоî buf¿¡ ÀúÀåÇÏ°í ÀÐÀº ¹®ÀÚ ¼ö¸¦ ¹ÝȯÇÑ´Ù. abstract int read(char buf[], int off, int len) throws IOException ¹®ÀÚ ÀÔ·Â ½ºÆ®¸²¿¡¼ len ¸¸ÅÀ» Àоî buf[]ÀÇ off À§Ä¡¿¡ ÀúÀåÇÏ°í ÀÐÀº ¹®ÀÚ ¼ö¸¦ ¹ÝȯÇÑ´Ù. int read(CharBuffer target) throws IOException CharBuffer ÇüÀÎ target¿¡ ¹®ÀÚ¿À» ÀÐ¾î ¿Â´Ù. boolean ready() throws IOException ¹®ÀÚ ÀÔ·Â ½ºÆ®¸²ÀÌ ÁغñµÇ¾ú´ÂÁö ¸®ÅÏÇÑ´Ù. void reset() throws IOException ¹®ÀÚ ÀÔ·Â ½ºÆ®¸²À» markµÈ À§Ä¡·Î µÇµ¹¸°´Ù. long skip(long l) throws IOException ÁÖ¾îÁø °³¼ö l ¸¸ÅÀÇ ¹®ÀÚ¸¦ °Ç³Ê¶Ú´Ù. ¨è Writer Ŭ·¡½º Writer Ŭ·¡½º´Â Character ´ÜÀ§ÀÇ Ãâ·ÂÀ» ´ëÇ¥ÇÏ´Â ÃÖ»óÀ§ Ãß»ó Ŭ·¡½ºÀÌ´Ù. Reader Ŭ·¡½º¿Í ¸¶Âù°¡Áö·Î Ãß»ó Ŭ·¡½ºÀ̱⠶§¹®¿¡ °´Ã¼¸¦ »ý¼ºÇÒ ¼ö ¾øÀ¸¸ç ÈÄ¼Õ Å¬·¡½ºÀÇ ·¹ÆÛ·±½º º¯¼ö·Î ¾²ÀÏ ¼ö ÀÖ´Ù. ´ëÇ¥ÀûÀÎ ¸Þ¼Òµå´Â write() ¸Þ¼ÒµåÀε¥ char ´ÜÀ§·Î Ãâ·ÂÇÏ´Â °Í°ú ÇÔ²² StringÀ» Ãâ·ÂÇÏ´Â °Íµµ °¡´ÉÇÏ´Ù. Ãâ·ÂÀº ¹öÆÛ·Î ³ª°¡¸ç flush() ¸Þ¼Òµå¸¦ ÀûÀýÇÑ ¶§¿¡ È£ÃâÇÏ¿© ¹öÆÛ¿¡¼ Á÷Á¢ µµÂø ÁöÁ¡À¸·Î µ¥ÀÌÅ͸¦ Àü¼ÛÇÑ´Ù. * Writer Ŭ·¡½ºÀÇ ¸Þ¼Òµå Writer append(char c) throws IOException Writer¿¡ Character c ¸¦ Ãß°¡ÇÑ´Ù. Writer append(CharSequence csq) throws IOException Writer¿¡ CharSequence csq ¸¦ Ãß°¡ÇÑ´Ù. Writer append(CharSequence csq, int start, int end) throws IOException Writer¿¡ CharSequence csq ÀÇ start ºÎÅÍ end±îÁöÀÇ ¹®ÀÚ¸¦ Ãß°¡ÇÑ´Ù. abstract void close() throws IOException ¹®ÀÚ Ãâ·Â ½ºÆ®¸²À» ´Ý´Â´Ù. abstract void flush() throws IOException ¹öÆÛ¿¡ ³²Àº Ãâ·Â ½ºÆ®¸²À» Ãâ·ÂÇÑ´Ù. void write(String s) throws IOException ÁÖ¾îÁø ¹®ÀÚ¿ s¸¦ Ãâ·ÂÇÑ´Ù. void write(char buf[]) throws IOException bufÀÇ ³»¿å¤·À» Ãâ·ÂÇÑ´Ù. void write(char buf[], int off, int len) throws IOException bufÀÇ off À§Ä¡ºÎÅÍ len ¸¸ÅÀÇ ¹®ÀÚ¸¦ Ãâ·ÂÇÑ´Ù. void write(String s, int off, int len) throws IOException ÁÖ¾îÁø ¹®ÀÚ¿ s¿¡ ÀÖ´Â ¹®ÀÚµéÀ» off À§Ä¡ºÎÅÍ len ¸¸Å Ãâ·ÂÇÑ´Ù.
|