본문으로 바로가기

이미지 웹 출력

category Backend/Spring 2020. 11. 6. 14:38
반응형
String fullPath		= "풀패스";
File file 			= new File(fullPath.replace("//","/"));

System.out.println("fullPath=============>"+ fullPath);

if(!file.exists() || !file.isFile()){
	file 			= new File("no_image.gif");
}

FileInputStream	fis			= null;
FileChannel ins				= null;
WritableByteChannel out		= null;

try{
    fis		= new FileInputStream(file);
    ins		= fis.getChannel();
    out		= Channels.newChannel(res.getOutputStream());
    ins.transferTo(0,ins.size(),out);
}catch(Exception e){
	e.printStackTrace();
}finally{
    try{if(out != null) out.close();}catch(Exception e){e.printStackTrace();}
    try{if(ins != null) ins.close();}catch(Exception e){e.printStackTrace();}
    try{if(fis != null) fis.close();}catch(Exception e){e.printStackTrace();}
}
반응형