JAVA/JAVA IO

[ java ] FileDescriptor 클래스를 이용한 스트림 생성

nineDeveloper 2016. 3. 9. 19:55
728x90
반응형
FileDescriptor 클래스는 물리적 파일에 대한 현재의 연결을 나타내기 위한 클래스 이다.
input 또는 output 스트림의 인스턴스에서 getFD() 메서드로 FileDescriptor 클래스의 인스턴스를 
얻을 수 있다.

ex 
String fileName = "abc.def";
String dirPath = "aaa/bbb/ccc";

File dir = new File(dirPath);
File file = new File (dir,fileName);

  FileDescriptor fd = null;
FileOutputStream fos = null;
  
try {
 fos = new FileOutputStream("");
 fd = fos.getFD();
  } catch (Exception e) {
                 .... 
  }

FileDescriptor 클래스의 인스턴스인 fd는
현재의 연결을 참조하기 때문에 원래의 스트림과 읽기 또는 쓰기 권한이 일치하는 스트림을 생성하는데
사용할 수 있다.

ex
FileOutputStream fos2 = new FileOutputStream(fd);

이미 존재하는 물리적파일에대한 참조이므로 Exception이 없어요~~~

 

728x90
반응형