gpt4 book ai didi

java - jsp txt 文件下载给我 jsp 内容

转载 作者:行者123 更新时间:2023-12-01 10:58:26 24 4
gpt4 key购买 nike

我有一个jsp项目,在我的项目中我想从该位置下载一个txt文件。代码确实有效,但文件的内容实际上是jsp索引页内容,我不知道这是怎么发生的。

    String filename = "Teste.txt";   
String filepath = "D:\\Online Secure File Transfer System\\project";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");

java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename);

int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();

最佳答案

我认为您的文件路径有问题,请勿附加字符串

  String filename = "Teste.txt"; 
String filepath = "D:\\Online Secure File Transfer System\\project\\Teste.txt";
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");
java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath);

int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();

关于java - jsp txt 文件下载给我 jsp 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33475128/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com