怎么正确使用renderFile呢?

QQ截图20170205222300.png


QQ截图20170205222327.png


怎么正确使用renderFile呢?要将test.xls下载下来。

评论区

lyq027

2017-02-05 22:35

去掉PathKit就可以了,只是不明白,为什么去掉就可以,加上就不行?路径不是一样吗

Adam

2017-02-06 08:44

getWebRootPath()返回的是WebRoot目录,你将test.xls移到WebRoot目录下就行了!

杜福忠

2017-02-06 10:47

源码中这样写到:
//2.0 这样的__________________________________________
public FileRender(File file) {
this.file = file;
}

public FileRender(String fileName) {
fileName = fileName.startsWith("/") ? webRootPath + fileName : fileDownloadPath + fileName;
this.file = new File(fileName);
}


//3.0 这样的__________________________________________
public FileRender(File file) {
if (file == null) {
throw new IllegalArgumentException("file can not be null.");
}
this.file = file;
}

public FileRender(String fileName) {
if (StrKit.isBlank(fileName)) {
throw new IllegalArgumentException("fileName can not be blank.");
}

String fullFileName;
fileName = fileName.trim();
if (fileName.startsWith("/") || fileName.startsWith("\\")) {
if (baseDownloadPath.equals("/")) {
fullFileName = fileName;
} else {
fullFileName = baseDownloadPath + fileName;
}
} else {
fullFileName = baseDownloadPath + File.separator + fileName;
}

this.file = new File(fullFileName);
}

lyq027

2017-02-06 16:46

@杜福忠 感谢,了解了

热门反馈

扫码入社