간단한 회사 웹 메일 만들던 중 메일 발송 부분에서 자료 첨부를 Struts 의 FormBean 을 이용해서
파일을 보내는데 nio 를 이용해 보려고 했다.
폼 파일에서는 FormFile.getInputStream() 이라는 것만 제공해 주는데..
무식하게 스리 getInputStream() 으로 반납되는 InputStream 을 FileInputStream 으로 바꾸려
뻘짓거리를 ㅡㅡ;;
그래서 API 를 뒤져보니.. java.nio.channels 클래스를 보니 newChannel() 메소드 발견~
아래와 같이 처리 함.
File file = new File("경로","파일명");
InputStream is = formFile.getInputStream();
ReadableByteChannel byteChannel = Channels.newChannel( is )
FileChannel outputChannel = new FileOutputStream(file).getChannel();
outputChannel.transferFrom(byteChannel, 0, is.available());
일단 되는것 확인...
Channels 클래스에 InputStream, OutputStream, Reader, Writer 로 변환해 주는게 다 모여있넹.
대충 알았으니 이제 놀자 ㅋㅋ
'JAVA > JSE' 카테고리의 다른 글
[펌] 손쉬운 정적 분석 툴로 버그 잡기 (0) | 2005.05.11 |
---|---|
FileFilter... 까먹기 싫어~~~ (0) | 2005.02.12 |
[펌] Sorting Algorithm (0) | 2005.01.15 |
[link] 자바 검색 봇~ (0) | 2005.01.11 |
[펌] [Collection Framework ] List, Set and Map (0) | 2004.12.29 |