nio
nio패키지
http://www.onjava.com/pub/a/onjava/2002/10/02/javanio.html
http://www.onjava.com/pub/a/onjava/2002/09/04/nio.html
파일복사
public static void fileCopyMapped(String from, String to) throws Exception{
FileInputStream fis = null;
FileOutputStream fos = null;
FileChannel in = null;
FileChannel out = null;
try{
fis = new FileInputStream(from);
fos = new FileOutputStream(to);
in = fis.getChannel();
out = fos.getChannel();
MappedByteBuffer m = in.map(FileChannel.MapMode.READ_ONLY,0, in.size());
out.write(m);
// 두줄을 in.transferTo(0,in.size(),out);
} catch (Exception e){
e.printStackTrace();
throw e;
} finally{
if (out!=null) out.close();
if(in!=null) in.close();
if(fos!=null) fos.close();
if(fis!=null) fis.close();
}
}
History
Last edited on 06/17/2008 15:26 by benelog
Comments (0)