From 69e2baf5518079bfc16cfadc2fb29842fb3de85d Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期二, 14 一月 2020 21:02:48 +0800
Subject: [PATCH] 加入userName

---
 Api/src/main/java/com/java110/api/rest/GetPhotoByInst.java |   94 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/Api/src/main/java/com/java110/api/rest/GetPhotoByInst.java b/Api/src/main/java/com/java110/api/rest/GetPhotoByInst.java
new file mode 100644
index 0000000..72e69c5
--- /dev/null
+++ b/Api/src/main/java/com/java110/api/rest/GetPhotoByInst.java
@@ -0,0 +1,94 @@
+package com.java110.api.rest;
+
+import org.apache.commons.io.FileUtils;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.StringUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
+/**
+ * @ClassName GetPhotoByInst
+ * @Description TODO
+ * @Author wuxw
+ * @Date 2019/8/28 22:49
+ * @Version 1.0
+ * add by wuxw 2019/8/28
+ **/
+public class GetPhotoByInst {
+
+    final static String PHOTO_INFO_PATH= "photoInfo.txt";
+    final static String DEFAULTE_PHOTO_DIR= "./Api/photos/";
+
+    public static void main(String[] args) {
+        //璇诲彇鏂囦欢
+        Reader reader = null;
+        String sb = "";
+        try {
+            InputStream inputStream = new ClassPathResource(PHOTO_INFO_PATH).getInputStream();
+            //InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(File.separator + filePath);
+            reader = new InputStreamReader(inputStream, "UTF-8");
+            int tempChar;
+            StringBuffer b = new StringBuffer();
+            while ((tempChar = reader.read()) != -1) {
+                b.append((char) tempChar);
+            }
+            sb = b.toString();
+
+            String[] strs = sb.split("\n");
+
+            for(String str : strs){
+                dealPhoto(str);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    private static void dealPhoto(String str) {
+
+        String[] tmpPhotoPaths = str.split("\\|");
+
+        String instId = tmpPhotoPaths[0];
+        String photoUrl = tmpPhotoPaths[1];
+
+        downloadFromUrl(photoUrl,DEFAULTE_PHOTO_DIR,"qhdx_"+instId+"_17.jpg");
+        //downloadFromUrl(photoUrl,DEFAULTE_PHOTO_DIR,instId+".jpg");
+    }
+
+
+    /**
+     * 鏂囦欢涓嬭浇鐨勬柟娉�
+     * @param  url 鍦板潃
+     * @param  dir 鐩綍
+     * @return String fileName
+     */
+    public static String downloadFromUrl(String url, String dir,String fileName) {
+
+        try {
+            URL httpurl = new URL(url);
+            //	fileName = getFileNameFromUrl(url);
+            //String[] us=url.split("/");
+            //fileName=us[us.length-1];
+            System.out.println("fileName:"+fileName);
+            File f = new File(dir + fileName);
+            FileUtils.copyURLToFile(httpurl, f);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "Fault!";
+        }
+        return fileName;
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0