//下载资源 試し{ URLのurlfile = NULL; HttpURLConnectionのhttpUrl = NULL; BufferedInputStreamをビス= NULL; BufferedOutputStreamがBOS = NULL; urlfile =新しいURL(downloadPath)。 httpUrl =(HttpURLConnectionの)urlfile.openConnection(); httpUrl.setRequestProperty( "クッキー"、クッキー); //字符串 httpUrl.connect(); //获取文件名 地図<文字列、リストの<string >>マップ= httpUrl.getHeaderFields(); 一覧<文字列>処分= map.get( "コンテンツディスポジション"); 文字列filename = disposition.get(0)。 ファイル名= filename.substring(filename.indexOf( "=")+ 1)。 ファイルf =新しいファイル(パス+ File.separator +ファイル名); ビス=新たにBufferedInputStream(httpUrl.getInputStream())。 BOS =新たなBufferedOutputStream(新たFileOutputStream(F))。 int型のlen = 2048; バイト[] B =新しいバイト[LEN]。 (!(LEN = bis.read(B))= -1){一方 bos.write(B、0、LEN)。 } bos.flush()。 bos.close(); bis.close(); httpUrl.disconnect(); moveToSuccessFolders(パス、ファイル名、BaseConfig.fileDownloadSuccess)。 }キャッチ(IOExceptionを電子){ logger.info( "-------- LANDSAT ---------- downloadId失敗しました:" + ID)。 e.printStackTrace(); }
プライベート(fromPath文字列、文字列のファイル名、文字列toPath){無効moveToSuccessFolders ;文字列startPath File.separator + + fileNameに= fromPath 文字列EndPath = toPath; 試みは、{ スタートファイル=新しい新しいファイル(startPath)をファイル; //ファイルがコピーが存在する場合には、失敗した ファイルをTMPFILE =新しいファイル(endPath); // ファイルフォルダのパスを取得する (!tmpFile.exists()){場合 //が作成された新規フォルダ作成せずにフォルダを作成するかどうかを決定する tmpFile.mkdirsを(); } (スタートファイルのiF。 renameTo(新しい新しいファイル(EndPath File.separator + + startFile.getName()))){ }他{ logger.info(startFile.getName()+ "ファイルを移動するために失敗した!"); } }キャッチ(例外E) { e.printStackTrace(); } }