|
@@ -1,9 +1,17 @@
|
|
package cn.com.qmth.print.manage.utils;
|
|
package cn.com.qmth.print.manage.utils;
|
|
|
|
|
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.BufferedInputStream;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.net.URLDecoder;
|
|
import java.net.URLDecoder;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 路径工具
|
|
* 路径工具
|
|
@@ -12,6 +20,8 @@ import java.net.URLDecoder;
|
|
*/
|
|
*/
|
|
public class PathUtil {
|
|
public class PathUtil {
|
|
|
|
|
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(PathUtil.class);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取标准路径
|
|
* 获取标准路径
|
|
*
|
|
*
|
|
@@ -136,6 +146,32 @@ public class PathUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static InputStream getStream(String path) {
|
|
|
|
+ try {
|
|
|
|
+ ClassLoader classLoader = PathUtil.class.getClassLoader();
|
|
|
|
+ URL url = classLoader.getResource(path);
|
|
|
|
+ return url.openStream();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void outputFile(HttpServletResponse response, InputStream inputStream, String fileName) {
|
|
|
|
+ try {
|
|
|
|
+ BufferedInputStream br = new BufferedInputStream(inputStream);
|
|
|
|
+ String fName = URLEncoder.encode(fileName, "UTF-8");
|
|
|
|
+
|
|
|
|
+ response.reset();
|
|
|
|
+ response.setContentType("application/x-msdownload");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + fName);
|
|
|
|
+ IOUtils.copy(br, response.getOutputStream());
|
|
|
|
+ br.close();
|
|
|
|
+// outStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error("请求出错:{}", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取windows盘符
|
|
* 获取windows盘符
|
|
*
|
|
*
|