我正在开发Spring Jhipster java应用程序,前端是angularjs。 我的要求是在csv文件中导出数据,然后将导出的文件下载到浏览器的下载路径。
我知道可以使用servlet完成,但是我们没有使用servlet,那么如果没有使用核心java代码的servlet,我怎么能完成。
答案 0 :(得分:0)
我很困惑,如果您要导出csv文件并且您拥有该文件对象,那么您可以使用FileUtils.copyFile(source, dest);
或
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(); }}
希望它有用。