|
@@ -1,9 +1,12 @@
|
|
|
package com.zskk.control;
|
|
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
@@ -153,7 +156,37 @@ public class ViewController extends Controller {
|
|
|
renderText(e.toString());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ public static String getFileWithUrl(String url, String filename) {
|
|
|
+
|
|
|
+ Request request = new Request.Builder().url(url).build();
|
|
|
+ try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
+ if (!response.isSuccessful())
|
|
|
+ throw new IOException("Unexpected code " + response);
|
|
|
+ InputStream inputStream = response.body().source().inputStream();
|
|
|
+ // 本地文件夹目录(下载位置)
|
|
|
+ String folder = PropKit.get("oss_localPath");
|
|
|
+ // 下载文件保存位置
|
|
|
+ String savepath = folder + "/" + filename;
|
|
|
+ BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savepath)));
|
|
|
+ byte[] data = new byte[1024];
|
|
|
+ int len;
|
|
|
+ int available = inputStream.available();
|
|
|
+ while ((len = inputStream.read(data)) != -1) {
|
|
|
+ bufferedOutputStream.write(data, 0, len);
|
|
|
+ }
|
|
|
+ bufferedOutputStream.flush();
|
|
|
+ bufferedOutputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+
|
|
|
+ return savepath;
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ return "";
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 日期字符串格式转换年月日时分秒
|
|
|
*
|