Some tips on downloading !! (How to bring up the dialog box !)

Source: Internet
Author: User

Note: inputstream cannot be assigned between two different classes. It can only be obtained directly !!

Example of remote FTP download:
// Set this item to tell the servlet that the object is downloaded, not a webpage or TXT. (a dialog box is displayed)
Response. setcontenttype ("application/OCTET-STREAM ");

// When intputstream is used, use the following.
Servletoutputstream outputstream = response. getoutputstream ();

// The Problem of converting and downloading Chinese names.
String fpath = new string (filename. getbytes ("GBK"), "iso8859_1 ");

// Set the downloaded file name to be the same as the original file name.
Response. setheader ("content-disposition ",
"Attachment; filename = \" "+ fpath +
"\"");
System. Out. println (reffile. getfilename ());

Ftpclient = new ftpclient ();

// Connect to the FTP server
Ftpclient. Connection (severurl)


If (reffile! = NULL & (reffile. getfilesize () <1024*1024*10 )){
Temremote = new string ("\" + reffile. getfilename (). getbytes ("gb2312"), "iso-8859-1 ");
Inputstream = ftpclient. retrievefilestream (temremote );
System. Out. println ("00001 ");
}
Else if (reffile! = NULL & (reffile. getfilesize ()> 1024*1024*10 )){
Temremote = new string (reffile. getmetaurl () + "\" +
Reffile. getfilename (). getbytes ("gb2312"), "iso-8859-1 ");
Inputstream = ftpclient. retrievefilestream (temremote );
}
System. Out. println ("<10m =" + "\" + reffile. getfilename ());
System. Out. println ("> 10 m =" + reffile. getmetaurl () + "\" +
Reffile. getfilename ());
Int I;
Int chunk = inputstream. Available ();
System. Out. println ("chunk data length =" + chunk );
// The byte array accepts the file data
Byte [] buffer = new byte [chunk];
Int length =-1;
If (inputstream = NULL ){
System. Out. println ("the input stream is empty !! ");
}
While (length = inputstream. Read (buffer ))! =-1 ){
System. Out. println ("length Data Length =" + length );
Outputstream. Write (buffer, 0, length); // read the stream and save it in the byte array
}

Inputstream. Close ();
Outputstream. Flush ();
Outputstream. Close ();

}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.