Home > Back-end >  Httpclient request remote file download
Httpclient request remote file download

Time:12-02

In the httpclient using the get pass after a request to a remote server, only return a file stream, how to download this file??

CodePudding user response:

https://bbs.csdn.net/topics/397403076

CodePudding user response:


/* ** @ param in the input stream 
* @ param fileName to save to file such as/data/img/fun. PNG
*/
Public static void fun (InputStream in, String fileName) {
The File File=new File (fileName);
FileOutputStream FileOutputStream=null;
Try {
FileOutputStream=new fileOutputStream (file);
int i;
Byte [] TMP=new byte [1024].
While ((I=in the read (TMP))!=1) {
FileOutputStream. Write (TMP, 0, I);
}
FileOutputStream. Flush ();
} the catch (Exception e) {
e.printStackTrace();
} the finally {
Try {
If (fileOutputStream!=null) {

FileOutputStream. Close ();
}
If (in!=null) {
in.close();
}
{} the catch (IOException ignore)
}
}
}

CodePudding user response:

File stream cannot convert file?

CodePudding user response:

Why back to the file stream, not the file location of the project
  • Related