単一のファイル・サーバのリモートメソッドをダウンロード

转载自博客:HTTPS://www.cnblogs.com/chafe/p/6408516.html 

パブリック
静的 ボイドdownloadFile(文字列remoteFilePath、列localFilePath){ URL urlfile = NULL ; HttpURLConnectionのhttpUrl = nullを BufferedInputStreamをビス = NULL ; BufferedOutputStreamがBOS = nullを ファイルf = 新しいファイル(localFilePath)。 試す { urlfile = 新しいURL(remoteFilePath)。 httpUrl =(HttpURLConnectionの)urlfile.openConnection(); httpUrl.connect(); ビス = 新たにBufferedInputStream(httpUrl.getInputStream())。 BOS = 新たなBufferedOutputStream(たFileOutputStream(F))。 int型のlen = 2048 ; バイト [] B = 新しい バイト[LEN]。 一方、(!(LEN = bis.read(B))= -1 { bos.write(B、 0 、LEN)。 } のSystem.out.println( "上传成功" )。 bos.flush()。 bis.close(); httpUrl.disconnect(); } キャッチ(例外e) { e.printStackTrace(); } 最後に { 試みる { bis.closeを(); bos.close(); } キャッチ(IOExceptionを電子) { e.printStackTrace(); } } } // パブリック静的無効メイン(文字列[] args){ // 文字列remoteFilePath =」http://172.18.49.196:9088 / easkLogAnalyse /アップロード/ IOS_AUDIT_LOG_20170207115053_18143481737.log "; // 文字列localFilePath =" F:/createFile/createFile/IOS_AUDIT_LOG_20170207115053_18143481737.log "; // downloadFile(remoteFilePath、localFilePath); // }

 

おすすめ

転載: www.cnblogs.com/mangwusuozhi/p/11127614.html