简体   繁体   English

如何在没有servlet的下载路径下从浏览器下载文件

[英]How to download file from browser at download path without servlet

I am working on Spring Jhipster java application with front end in angularjs. 我正在使用Anglejs的前端开发Spring Jhipster Java应用程序。 My requirement is to export data in csv file then download that exported file to download path of browser. 我的要求是将数据导出到csv文件中,然后将导出的文件下载到浏览器的下载路径。

I know it can be done using servlet, but we are not using servlet then how can I accomplish without servlet using core java code. 我知道可以使用servlet来完成,但是我们不使用servlet,那么如果没有使用核心Java代码的servlet怎么办。

I am confused, if you are exporting csv file and you have that file object then you can easily copy this file with FileUtils.copyFile(source, dest); 我很困惑,如果您要导出csv文件,并且具有该文件对象,则可以使用FileUtils.copyFile(source, dest);轻松复制此文件FileUtils.copyFile(source, dest); or 要么

private static void copyFileUsingChannel(File source, File dest) throws IOException {
FileChannel sourceChannel = null;
FileChannel destChannel = null;
try {
    sourceChannel = new FileInputStream(source).getChannel();
    destChannel = new FileOutputStream(dest).getChannel();
    destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
   }finally{
       sourceChannel.close();
       destChannel.close();   }}

Hope it is helpful. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM