|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--org.kwis.msp.io.File
파일에 대한 읽기/쓰기와 같은 기본적인 기능과 Stream 기능 지원을 위한 클래스입니다.
파일이름은 모두 절대경로로 되어 있습니다. 실제로는 플랫폼에서 허용하는 디렉토리안에서 모든 파일을 만들고 지울 수 있게 되어있습니다. 사용자입장에서는 플랫폼에서 어떤 식으로 지원하든 상관없이 절대경로로 사용하면 됩니다.
구분자(separator)의 경우 유닉스 시스템의 관행을 따랐습니다.
그러므로 "/"를 사용하면 됩니다.
FileSystem 클래스와 마찬가지로 경로를 지정하는 메소드의 경우 접근 방법에 대한 제한이 있습니다. 접근방법은 아래와 같은 3가지가 있습니다.
FileSystem.PRIVATE_ACCESS, FileSystem.SHARED_ACCESS, FileSystem.SYSTEM_ACCESS
아래와 같은 메소드를 호출하기 위해서는 반드시 접근 수준을 명시해야 합니다.
어떤 모드로 open하느냐에 따라 열 수 있는 stream의 갯수가 제한되어 있습니다.
File 메소드 중에서는 low level로 보다 빠른 접근을 가능하게 하는 API가 있습니다.
read(byte[])
read(byte[], int, int)
write(byte[])
write(byte[], int, int)
write(int)
seek(int)
sizeOf()
openInputStream(),
openOutputStream(),
openDataInputStream(),
openDataOutputStream()
을 이용해서 파일에서 읽고 파일에 쓰는 것 보다 빠르게 접근할 수 있습니다.
| Field Summary | |
protected int |
maxInputStream
열 수 있는 최대 InputStream 갯수 |
protected int |
maxOutputStream
열 수 있는 최대 OutputStream 갯수 |
static int |
READ_ONLY
읽기만 할 때 쓰는 옵션 |
static int |
READ_WRITE
읽기와 쓰기를 동시에 하기 위한 옵션 |
static int |
WRITE
기존의 파일이 있으면 파일의 제일 끝부터 쓰기 시작하기 위한 옵션 |
static int |
WRITE_TRUNC
기존의 파일이 있으면 크기를 0으로 만들고 열기위한 옵션 |
| Constructor Summary | |
File(String filename,
int mode)
응용프로그램 자신만의 디렉토리에 지정된 파일을 생성합니다. |
|
File(String filename,
int mode,
int flag)
파일을 생성합니다. |
|
| Method Summary | |
void |
close()
파일을 닫습니다. |
DataInputStream |
openDataInputStream()
DataInputStream을 가져옵니다.
|
DataOutputStream |
openDataOutputStream()
DataOutputStream을 가져옵니다.
|
InputStream |
openInputStream()
InputStream을 가져옵니다.
|
OutputStream |
openOutputStream()
OutputStream을 가져옵니다.
|
int |
read(byte[] buf)
input stream으로 부터 데이타를 읽어 들입니다. |
int |
read(byte[] buf,
int off,
int len)
input stream으로 부터 데이타를 len 바이트수만큼 읽어 들입니다.
|
void |
seek(int pos)
파일 포인터를 특정 위치로 옮깁니다. |
int |
sizeOf()
파일의 크기를 알려줍니다. |
int |
write(byte[] buf)
파일에 buf에 들어 있는 데이타를 buf의 길이만큼 씁니다.
|
int |
write(byte[] buf,
int off,
int len)
파일에 buf에 들어 있는 데이타를 off부터 시작해서 len만큼 씁니다.
|
int |
write(int b)
파일에 한 바이트만 쓸 때 사용합니다. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected int maxInputStream
protected int maxOutputStream
public static final int READ_ONLY
public static final int WRITE
public static final int WRITE_TRUNC
public static final int READ_WRITE
| Constructor Detail |
public File(String filename,
int mode)
throws IOException
READ_ONLY read only로 읽습니다. 만약 쓰려고 하면 exception이 발생합니다.
WRITE 현재 파일을 유지하고 파일 포인터가 제일 뒤에 위치하게 됩니다.
WRITE_TRUNC 파일이 truncation됩니다. 즉, 파일을 여는 순간 파일 길이는 0으로 됩니다.
READ_WRITE read와 write를 동시에 할 수 있습니다.
filename - 열고자 하는 파일의 절대 경로mode - READ_ONLY, WRITE,WRITE_TRUNC, READ_WRITE중 하나IOException - 파일을 열 수 없을 경우FileSystem
public File(String filename,
int mode,
int flag)
throws IOException,
SecurityException
READ_ONLY read only로 읽습니다. 만약 쓰려고 하면 exception이 발생합니다.
WRITE 현재 파일을 유지하고 파일 포인터가 제일 뒤에 위치하게 됩니다.
WRITE_TRUNC 파일이 truncation됩니다. 즉, 파일을 여는 순간 파일 길이는 0으로 됩니다.
READ_WRITE read와 write를 동시에 할 수 있습니다.
filename - 열고자 하는 파일의 절대 경로mode - READ_ONLY, WRITE,WRITE_TRUNC, READ_WRITE중 하나flag - FileSystem.PRIVATE_ACCESS, FileSystem.SHARED_ACCESS, FileSystem.SYSTEM_ACCESS중 하나IOException - 파일을 열 수 없을 경우SecurityException - 접근할 수 없는 디렉토리를 접근할려고 할려고할 경우FileSystem| Method Detail |
public InputStream openInputStream()
throws IOException
InputStream을 가져옵니다.
열 수 있는 InputStream갯수는 DataInputStream포함 최대 한 개입니다.InputStreamIOException - 파일이 아직 열리지 않았거나 이미 InputStream이 열려 있을 경우InputStream
public DataInputStream openDataInputStream()
throws IOException
DataInputStream을 가져옵니다.
열 수 있는 DataInputStream갯수는 InputStream포함해서 최대 한 개입니다.DataInputStreamIOException - 파일이 아직 열리지 않았거나 이미 InputStream이 열려 있을 경우DataInputStream
public OutputStream openOutputStream()
throws IOException
OutputStream을 가져옵니다.
열 수 있는 OutputStream갯수는 DataOutputStream포함 최대 한 개입니다.OutputStreamIOException - 파일이 아직 열리지 않았거나 이미 OutputStream이 열려 있을 경우OutputStream
public DataOutputStream openDataOutputStream()
throws IOException
DataOutputStream을 가져옵니다.
열 수 있는 DataOutputStream갯수는 OutputStream포함해서 최대 한 개입니다.DataOutputStreamIOException - 파일이 아직 열리지 않았거나 이미 OutputStream이 열려 있을 경우DataOutputStream
public void close()
throws IOException
IOException - 파일을 제대로 닫을 수 없을 경우
public int write(int b)
throws IOException
b - 쓸 한 바이트IOException - close함수로 닫혀진 File에서 write하는 경우이거나, 제대로 쓸 수 없을 경우
public int write(byte[] buf)
throws IOException,
NullPointerException
buf에 들어 있는 데이타를 buf의 길이만큼 씁니다.
buf가 null일 경우에 NullPointerException을 발생시킵니다.buf - 실제 데이타가 들어있는 byte arrayIOException - close함수로 닫혀진 File에서 write하는 경우이거나, 제대로 쓸 수 없을 경우NullPointerException - buf가 null인 경우
public int write(byte[] buf,
int off,
int len)
throws IOException,
NullPointerException
buf에 들어 있는 데이타를 off부터 시작해서 len만큼 씁니다.
buf가 null일 경우에 NullPointerException을 발생시킵니다.buf - 실제 데이타가 들어있는 byte arrayoff - 쓸 데이타가 들어있는 위치len - 실제로 쓸 데이타 크기IOException - close함수로 닫혀진 File에서 write하는 경우이거나, 제대로 쓸 수 없을 경우IOException - buf가 null인 경우
public int read(byte[] buf)
throws IOException,
NullPointerException
buf의 size만큼 읽어 들입니다.
만약 파일의 끝까지 모두 읽었을 경우 그 읽은 만큼만 buf에
저장하고, 저장된 갯수를 돌려줍니다. 그리고, 다음 read시에 -1을 돌려줍니다.buf - 읽은 데이타를 담을 바이트 배열IOException - close함수로 닫혀진 File에서 write하는 경우이거나, 제대로 읽을 수 없을 경우NullPointerException - buf가 null인 경우
public int read(byte[] buf,
int off,
int len)
throws IOException,
NullPointerException
len 바이트수만큼 읽어 들입니다.
len 만큼 읽지 못하고 EOF를 만나면 읽은 바이트수만큼을 buf에 저장해서 돌려줍니다.buf - 읽은 데이타를 담을 바이트 배열off - buf의 어디서 부터 읽은 데이타를 저장할 건지를 정하는 offsetlen - 얼마만큼 읽을 것인가를 나타냅니다.IOException - close함수로 닫혀진 File에서 write하는 경우이거나, 제대로 읽을 수 없을 경우NullPointerException - buf가 null인 경우
public void seek(int pos)
throws IOException
pos - 옮길 파일 포인터 위치, 반드시 파일의 처음부터의 절대 값이여야합니다.IOException - 파일 handle이 제대로 세팅되지 않았거나 파일 포인터를 옮기는 도중 에러가 발생했을 경우
public int sizeOf()
throws IOException
IOException - 파일 handle이 제대로 세팅되지 않았거나 크기를 읽어 오는도중 에러가 발생했을 경우