Chapter 18 - 데이터 입출력 확인문제

김태원·2023년 1월 31일
0

Chapter 18 - 데이터 입출력 확인문제

정답: 1

스트림은 입력 스트림과 출력 스트림으로 나뉘어 있다.

정답: 1

이미지 데이터는 InputStream으로만 읽을 수 있다.

정답: 3

read(byte[] b) 메소드는 입력 스트림으로부터 주어진 배열의 길이만큼만 읽을 수 있다.

정답: 1

flush() 메소드는 출력 스트림의 버퍼에 있는 데이터를 모두 출력시키고 버퍼를 비운다.

정답: 3

DataInputStream은 기본 타입인 boolean, char, short, int, long, float, double 값을 입력할 수 있는 보조 스트림이다.

정답: 3

두 클래스가 동일한 SerialVersionUID 상수값을 가지고 있어야 한다.

정답:

new FileReader(filePath);
new BufferedReader(fr);
rowData = br.readLine();
if (rowData == null) break;
System.out.println(++rowNumber + ": " + rowData);

정답: 4

PrintStream은 바이트 출력 스트림과 연결되고, PrintWriter는 문자 출력 스트림과 연결된다.

정답: 2

File 객체는 getPath() 등의 메소드를 이용해서 디렉터리 정보를 제공한다.

정답:

import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("원본 파일 경로: ");
        String orgPath = sc.nextLine();

        System.out.print("복사 파일 경로: ");
        String dstPath = sc.nextLine();

        File orgFile = new File(orgPath);
        if (!orgFile.exists()) {
            System.out.println("원본 파일이 존재하지 않습니다.");
            System.exit(0);
        }

        File dstFile = new File(dstPath);
        File parentFile = dstFile.getParentFile();
        if (!dstFile.getParentFile().exists()) {
            parentFile.mkdirs();
        }

        try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(orgPath));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dstPath));

            bis.transferTo(bos);
            bis.close();
            bos.close();

            System.out.println("복사가 성공되었습니다.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
profile
개발이 재밌어서 하는 Junior Backend Developer

0개의 댓글