|
|
@@ -315,13 +315,15 @@ public class ServiceFileUtil {
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
public static void downloadFile(String fileURL,String fileName, String destinationPath) throws IOException {
|
|
|
-
|
|
|
- String fullUrl = UriComponentsBuilder.fromHttpUrl(fileURL)
|
|
|
- .replaceQueryParam("fileName", fileName)
|
|
|
- .build()
|
|
|
- .toUriString();
|
|
|
-
|
|
|
-
|
|
|
+ String newUrl = "";
|
|
|
+ if(StringUtils.contains(fileName,"&")){
|
|
|
+ newUrl = StringUtils.replace(fileURL, "&fileName="+fileName, "");
|
|
|
+ }else {
|
|
|
+ newUrl = fileURL.replaceAll("&fileName=[^&]*$", "");
|
|
|
+ }
|
|
|
+ String encodeFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8);
|
|
|
+ // 拼接合法URL
|
|
|
+ String fullUrl = newUrl + "&fileName=" + encodeFileName;
|
|
|
URL url = new URL(fullUrl);
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
connection.setRequestMethod("GET");
|
|
|
@@ -329,7 +331,7 @@ public class ServiceFileUtil {
|
|
|
connection.setReadTimeout(5000); // 设置读取超时时间
|
|
|
int contentLength = connection.getContentLength(); // 获取文件大小
|
|
|
|
|
|
- System.out.println("Downloading file of size: " + contentLength + " bytes");
|
|
|
+ logger.info("Downloading file of size: " + contentLength + " bytes");
|
|
|
|
|
|
//目录路径许哟啊拼接文件名称
|
|
|
destinationPath += "/"+ fileName;
|
|
|
@@ -343,8 +345,7 @@ public class ServiceFileUtil {
|
|
|
while ((bytesRead = in.read(buffer)) != -1) {
|
|
|
out.write(buffer, 0, bytesRead);
|
|
|
}
|
|
|
-
|
|
|
- System.out.println("Download completed.");
|
|
|
+ logger.info("Download completed.");
|
|
|
} finally {
|
|
|
connection.disconnect();
|
|
|
}
|
|
|
@@ -356,7 +357,6 @@ public class ServiceFileUtil {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
public static void test() throws Exception {
|
|
|
Path dirPath = Paths.get("C:\\Users\\Administrator\\Desktop\\01\\一码管地相关\\数据库.docx");
|
|
|
String extension = FilenameUtils.getExtension(dirPath.toString());
|