您好,登錄后才能下訂單哦!
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//圖片壓縮
public class Demo2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//通知瀏覽器打開一副圖片
response.setHeader("content-type", "image/jpeg");
InputStream is = new FileInputStream(new File("D:/TOOL/MyEclipseSpace/day04/WebRoot/images/cc.jpg"));
OutputStream os = response.getOutputStream();
byte[] buf = new byte[1024];
int len = 0;
while((len = is.read(buf)) > 0)
{
os.write(buf,0,len);
}
is.close();
os.close();
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。