我有这个问题。我使用spring并将附件(doc,pdf,png ...)存储到服务器文件系统中。然后我将文件的路径和名称保存到我的数据库中。现在我怎样才能将此文件作为链接读取到浏览器中?
我想将文件写入网络位置并将该位置提供给浏览器。这是一个好习惯吗?但是可视化后如何删除文件?
我希望这个问题很清楚。
写我使用:
/** what write for reach temp-file folder (my project name is intranet)
I thougth TEMP_FOLDER=""/intranet/resources/temp-files/";
but It doesnt work. ioexception (The system cannot find the path specified)
*/
final static String TEMP_FOLDER=?????
public static String createTempFile(String originalPathFile,String fileName){
String tempPathFile="";
try {
InputStream inputStream = new FileInputStream(originalPathFile);
tempPathFile=TEMP_FOLDER+fileName;
File tempFile = new File(tempPathFile);
OutputStream out = new FileOutputStream(tempFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
out.close();
} catch (IOException ioe) {
System.out.println("Error while Creating File in Java" + ioe);
}
return tempPathFile;
}