File file = new File("파일 또는 디렉토리의 경로String getName() - 파일 또는 디렉토리의 이름을 반환
String getPath() - 파일 또는 디렉토리의 경로 이름을 반환
String getAbsolutePath() - 파일 또는 디렉토리의 절대 경로 이름을 반환
boolean exists() - 파일 또는 디렉토리가 존재하는지 여부를 테스트
boolean isFile() - 객체가 파일인지 확인
boolean isDirectory() - 객체가 디렉토리인지 확인
boolean mkdir() - 새로운 디렉토리를 생성 (상위 디렉토리가 존재해야 함)
boolean mkdirs() - 필요한 상위 디렉토리를 포함하여 새로운 디렉토리 생성
boolean delete() - 파일 또는 디렉토리를 삭제

int read()
throws IOException
- 입력 스트림에서 단일 바이트를 읽음
- 읽을 데이터가 없다면 -1을 반환
int read(byte[] b)
throws IOException
- 입력 스트림에서 byte 배열만큼 데이터를 읽음
- 읽은 바이트 수를 반환
int read(byte[] b, int off, int len)
throws IOException
- 지정된 길이(len)만큼 데이터를 읽어 byte 배열의 지정된 위치(off)에 저장
void close()
throws IOException
- 스트림을 종료하고 자원을 반납함
void write(int b)
throws IOException
- 출력 스트림에 한 바이트를 씀
void write(byte[] b)
throws IOException
- 출력 스트림에ㅔ byte 배열 전체를 씀
void write(byte[] b, int off, int len)
throws IOException
- 지정된 byte 배열의 특정 부분(off 부터 len길이 만큼)을 씀
void flush()
throws IOExcepption
- 출력 스트림에 남아 있는 데이터를 강제로 출력 (버퍼링된 스트림에 유용)
void close()
throws IOException
- 스트림을 종료하고 자원을 반납함
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Main {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("dog.png");
fos = new FileOutputStream("dog-copy.jpg");
int b;
while ((b=fis.read()) != -1) {
fos.write(b);
}
} catch (FileNotFoundException e) {
System.out.println("파일 없음 이슈");
} catch (IOException e) {
System.out.println("더큰 통로 입출력 이슈");
} finally {
try {
if (fis != null) {
fis.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
System.out.println();
}
}
}
}
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Main {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("dog.png");
fos = new FileOutputStream("dog-copy.jpg");
int b;
byte[] buffer = new byte[100];
while ((b=fis.read(buffer)) != -1) {
fos.write(buffer,0,b);
}
} catch (FileNotFoundException e) {
System.out.println("파일 없음 이슈");
} catch (IOException e) {
System.out.println("더큰 통로 입출력 이슈");
} finally {
try {
if (fis != null) {
fis.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
System.out.println();
}
}
}
}
int read()
throws IOException
- 입력 스트림에서 단일 문자를 읽음 (읽은 문자가 없으면 -1 반환)
int read(char[] cbuf)
throws IOException
- 입력 스트림에서 문자 배열만큼 읽음
int read(char[] cbuf, int off, int len)
throws IOException
- 저장된 길이(len)만큼 읽어 배열의 특정 위치(off)에 저장
void close()
throws IOException
- 스트림을 종료하고 자원을 반납함
void write(int c)
throws IOException
- 단일 문자를 출력
void write(char[] cbuf)
throws IOException
- 문자 배열을 출력
void write(char[] cbuf, int off, int len)
throws IOException
- 배열의 특정 부분 (off 부터 len 만큼)을 출력
void write(String str)
throws IOException
- 문자열을 출력
void flush()
throws IOException
- 출력 스트림에 남아 있는 데이터를 강제로 출력
void close()
throws IOException
- 스트림을 종료하고 자원을 반납함
import java.io.FileReader;
import java.io.IOException;
import java.io.FileWriter;
import java.io.FileNotFoundException;
public class Main {
public static void main(String[] args) {
FileReader fis = null;
FileWriter fos = null;
try {
fis = new FileReader("dog.txt");
fos = new FileWriter("dog-copy1.txt");
int b;
while ((b=fis.read()) != -1) {
fos.write(b);
}
} catch (FileNotFoundException e) {
System.out.println("파일 없음 이슈");
} catch (IOException e) {
System.out.println("더큰 통로 입출력 이슈");
} finally {
try {
if (fis != null) {
fis.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
System.out.println();
}
}
}
}
close()를 호출하면 노드 스트림의 close()까지 호출됨객체의 상태를 바이트 스트림으로 변환하여 저장하거나 전송할 수 있도록 하는 과정
직렬화된 바이트 스트림을 다시 객체로 복원하는 절차
ObjectOutputStream - 객체를 바이트 스트림으로 변환하는 스트림
ObjectInputStream - 바이트 스트림을 객체로 복원하는 스트림