CodeGym /ํ–‰๋™ /์ž๋ฐ” ๊ตฌ๋ฌธ /์ „์ฒด ํด๋ž˜์Šค ์ด๋ฆ„

์ „์ฒด ํด๋ž˜์Šค ์ด๋ฆ„

์ž๋ฐ” ๊ตฌ๋ฌธ
๋ ˆ๋ฒจ 2 , ๋ ˆ์Šจ 9
์‚ฌ์šฉ ๊ฐ€๋Šฅ
์ „์ฒด ํด๋ž˜์Šค ์ด๋ฆ„ - 1

"์•ˆ๋…•, ์•„๋ฏธ๊ณ . ๋ฐ˜ ์ „์ฒด ์ด๋ฆ„์— ๋Œ€ํ•ด ์•Œ๋ ค์ค„๊ฒŒ."

"์ด๋ฏธ ์•Œ๊ณ  ์žˆ๋“ฏ์ด ํด๋ž˜์Šค๋Š” ํŒจํ‚ค์ง€์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํด๋ž˜์Šค์˜ ์ „์ฒด ์ด๋ฆ„์€ ๋งˆ์นจํ‘œ๋กœ ๊ตฌ๋ถ„๋œ ๋ชจ๋“  ํŒจํ‚ค์ง€์˜ ์ด๋ฆ„๊ณผ ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ๋ช‡ ๊ฐ€์ง€ ์˜ˆ์ž…๋‹ˆ๋‹ค . "

ํด๋ž˜์Šค ์ด๋ฆ„ ํŒจํ‚ค์ง€ ์ด๋ฆ„ ์„ฑ๋ช…
String
java.lang java.lang. ๋ˆ
FileInputStream
java.io java.io. FileInputStream
ArrayList
์ž๋ฐ”.์œ ํ‹ธ java.util. ๋ฐฐ์—ด๋ชฉ๋ก
IOException
java.io java.io. IO์˜ˆ์™ธ ;

"์ฝ”๋“œ์—์„œ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ „์ฒด ์ด๋ฆ„์„ ํ‘œ์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์งง์€ ์ด๋ฆ„, ์ฆ‰ ํด๋ž˜์Šค ์ด๋ฆ„๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ 'ํด๋ž˜์Šค๋ฅผ ๊ฐ€์ ธ์™€์•ผ' ํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, ํด๋ž˜์Šค๋ฅผ ์„ ์–ธํ•˜๊ธฐ ์ „์— class, ๊ฐ€์ ธ์˜ค๊ธฐ๋ผ๋Š” ๋‹จ์–ด ๋’ค์— ๊ฐ€์ ธ์˜ค๋ ค๋Š” ํด๋ž˜์Šค์˜ ์ด๋ฆ„์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค . ๊ธฐ๋ณธ์ ์œผ๋กœ java.lang ํŒจํ‚ค์ง€์˜ ํด๋ž˜์Šค๋ฅผ ๊ฐ€์ ธ์˜ค๋ฏ€๋กœ ๊ฐ€์ ธ์˜ฌ ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค."

์ „์ฒด ํด๋ž˜์Šค ์ด๋ฆ„:
package com.codegym.lesson2;

public class FileCopy2
{
    public static void main(String[] args) throws java.io.IOException
    {
        java.io.FileInputStream fileInputStream =
                        new java.io.FileInputStream("c:\\data.txt");
        java.io.FileOutputStream fileOutputStream =
                        new java.io.FileOutputStream("c:\\result.txt");

        while (fileInputStream.available() > 0)
        {
            int data = fileInputStream.read();
            fileOutputStream.write(data);
        }

        fileInputStream.close();
        fileOutputStream.close();
    }
}

"๋‹ค์Œ์€ ์งง์€ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋Š” ์˜ˆ์ž…๋‹ˆ๋‹ค."

์งง์€ ํด๋ž˜์Šค ์ด๋ฆ„:
package com.codegym.lesson2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy
{
    public static void main(String[] args) throws IOException
    {
        FileInputStream fileInputStream =
                        new FileInputStream("c:\\data.txt");
        FileOutputStream fileOutputStream =
                        new FileOutputStream("c:\\result.txt");

        while (fileInputStream.available() > 0)
        {
            int data = fileInputStream.read();
            fileOutputStream.write(data);
        }

        fileInputStream.close();
        fileOutputStream.close();
    }
}

"์•Œ์•˜์–ด์š”."

"์—„์ฒญ๋‚œ."

์ฝ”๋ฉ˜ํŠธ
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION