|
@@ -1,6 +1,12 @@
|
|
|
package com.zskk.service;
|
|
|
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -9,6 +15,9 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
|
+import jcifs.smb.NtlmPasswordAuthentication;
|
|
|
+import jcifs.smb.SmbFile;
|
|
|
+import jcifs.smb.SmbFileInputStream;
|
|
|
import okhttp3.FormBody;
|
|
|
import okhttp3.OkHttpClient;
|
|
|
import okhttp3.Request;
|
|
@@ -77,11 +86,37 @@ public class DataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void downloadFileToFolder(String remoteUrl, String shareFolderPath, String fileName, String localDir) {
|
|
|
+ InputStream in = null;
|
|
|
+ OutputStream out = null;
|
|
|
+ try {
|
|
|
+ SmbFile remoteFile = new SmbFile(remoteUrl + shareFolderPath + "/" + fileName,NtlmPasswordAuthentication.ANONYMOUS);
|
|
|
+ File localFile = new File(localDir + File.separator + fileName);
|
|
|
+ in = new BufferedInputStream(new SmbFileInputStream(remoteFile));
|
|
|
+ out = new BufferedOutputStream(new FileOutputStream(localFile));
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ while (in.read(buffer) != -1) {
|
|
|
+ out.write(buffer);
|
|
|
+ buffer = new byte[1024];
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ out.close();
|
|
|
+ in.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
- Map <String,String> map = new HashMap<String,String>();
|
|
|
- map.put("institution_id", "47600001");
|
|
|
- map.put("num", "10");
|
|
|
- postWithParameters(GET_EXAM_URL, map);
|
|
|
+// Map <String,String> map = new HashMap<String,String>();
|
|
|
+// map.put("institution_id", "47600001");
|
|
|
+// map.put("num", "10");
|
|
|
+// postWithParameters(GET_EXAM_URL, map);
|
|
|
+ downloadFileToFolder("smb://192.168.1.140", "/VAIO/ConsoleTest", "Program.cs", "/Users/liutao/Desktop/GIT_CODE");
|
|
|
}
|
|
|
|
|
|
}
|