炫意html5
最早CSS3和HTML5移动技术网站之一

下载找不到文件

大佬们,我想要做的是下载限速。公司将软件上传,对其下载网速进行限速。现在限速下载接口算是写好了,前端访问后台页面并将文件下载下来我不会写。问的公司有经验的一个后端,现在现在效果是页面上显示访问成功,后台代码显示下载成功。但是找不到下载的文件在哪。请大佬们帮我看看前端代码怎么改。我第一次写代码,前端不会,后端不熟,呜呜呜,大佬们帮帮忙把。
下边是下载的代码
@Controller
@RequestMapping(“file”)
public class DownloadFileController {

@PostMapping("/limit")
public void limitDownloadFile(String file, HttpServletResponse response) throws IOException {
System.out.println("download file");
if (file == null) {
file = "C:/Users/jhsoft/Desktop/test.txt";
}
File downloadFile = new File(file);
System.out.println(downloadFile.getName());
FileInputStream fileInputStream = new FileInputStream(downloadFile);
response.setContentType("application/x-msdownload;");
response.setHeader("Content-disposition", "attachment; filename=" + new String(downloadFile.getName()
.getBytes("utf-8"), "ISO8859-1"));
response.setHeader("Content-Length", String.valueOf(downloadFile.length()));
ServletOutputStream outputStream = null;
try {
LimitInputStream limitInputStream = new LimitInputStream(fileInputStream, new BandwidthLimiter(1024));
long beginTime = System.currentTimeMillis();
outputStream = response.getOutputStream();
System.out.println("outputStream:");
System.out.println(outputStream.toString());
byte[] bytes = new byte[1024];
int read = limitInputStream.read(bytes, 0, 1024);
while (read != -1) {
outputStream.write(bytes);
read = limitInputStream.read(bytes, 0, 1024);
}
System.out.println(System.currentTimeMillis() - beginTime);
} finally {
fileInputStream.close();
if (outputStream != null) {
outputStream.close();
}
System.out.println("download success!");
}
}

}

这是前端内容:
<script type=”text/javascript”>
//页面一开始加载的时候会先执行这个方法里的东西
$(function (){
$.ajax({
type: “post”,
url: “/file/limit”,
data: {
“file”: “F:/项目restaurant/restaurant/restaurant/sql/text.txt”
},
success: function(res) {
console.log(“访问成功”);
}
});
});

回答

问题补充:

炫意HTML5 » 下载找不到文件

Java基础教程Android基础教程