ฉันมีเซิร์ฟเล็ตที่ดาวน์โหลดไฟล์ไปยังไคลเอนต์ที่ร้องขอ ตอนนี้เมื่อผู้ใช้ร้องขอดาวน์โหลดไฟล์ xml มันจะเริ่มดาวน์โหลดและเมื่อเสร็จแล้วไฟล์จะดูไม่สมบูรณ์ ข้อมูลบางส่วนหายไปที่ส่วนท้ายของไฟล์
รหัสของฉันดูเหมือนว่า:
File file = new File(location);
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=" + fileName);
FileInputStream fileIn = new FileInputStream(file);
OutputStream out = response.getOutputStream();
byte[] outputByte = new byte[4096];
int length = -1;
//copy binary contect to output stream
while((length = fileIn.read(outputByte)) > 0)
{
out.write(outputByte);
}
fileIn.close();
out.flush();
out.close();
รหัสของฉันดาวน์โหลดไฟล์ xml แบบเต็มไม่ได้อยู่ที่ไหน