Browse Source

文件加载,加入一个钟想对路径方式fileis = ClassLoader.getSystemResourceAsStream(url);

4.1.3.A
jueyue 7 years ago
parent
commit
204d87c7d2
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoadeImpl.java

+ 9
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoadeImpl.java View File

@@ -19,6 +19,7 @@ import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
@@ -37,15 +38,20 @@ public class FileLoadeImpl implements IFileLoader {
private static final Logger LOGGER = LoggerFactory.getLogger(FileLoadeImpl.class);
public byte[] getFile(String url) {
FileInputStream fileis = null;
InputStream fileis = null;
ByteArrayOutputStream baos = null;
try {
//先用绝对路径查询,再查询相对路径
try {
fileis = new FileInputStream(url);
} catch (FileNotFoundException e) {
String path = PoiPublicUtil.getWebRootPath(url);
fileis = new FileInputStream(path);
//获取项目文件
fileis = ClassLoader.getSystemResourceAsStream(url);
if (fileis == null) {
//最好再拿想对文件路径
String path = PoiPublicUtil.getWebRootPath(url);
fileis = new FileInputStream(path);
}
}
baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];


Loading…
Cancel
Save