Java 文件导出

文件导出

 public void downTemplateFile(String code, HttpServletResponse resp) {
        InputStream iStream = null;
        OutputStream outStrem = null;
        try {
            ImpExcelTmpl tmplFile = impExcelTmplService.getExcelTmplByCodeAndOrgRegister(code);
            String url = tmplFile.getFile_url();
            iStream = new FileInputStream(url);
            String fileName = tmplFile.getFile_name();
            String suffix = url.substring(url.lastIndexOf("."));
            fileName = new String((fileName + suffix).getBytes(), "ISO8859-1");
            resp.setContentType("multipart/form-data");
            resp.setCharacterEncoding("utf-8");
            resp.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
            outStrem = resp.getOutputStream();
            outStrem.write(StreamUtils.getBytes(iStream));
            outStrem.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (iStream != null) {
                try {
                    iStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outStrem != null) {
                try {
                    outStrem.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

excel 导出

  private void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook) throws IOException {
        try {
            response.setCharacterEncoding("UTF-8");
            response.setHeader("content-Type" , "application/vnd.ms-excel");
            response.setHeader("Content-Disposition" , "attachment;filename=" + URLEncoder.encode(fileName + ".xlsx" , "UTF-8"));
            workbook.write(response.getOutputStream());
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java中可以使用第三方库来操作KML文件。其中一个常用的库是JAK,它提供了一些类和方法用于创建和操作KML文件。以下是一个简单的示例代码,演示如何使用JAK库将数据导出为KML文件: ```java import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; import org.jak.Kml; import org.jak.KmlException; import org.jak.Placemark; import org.jak.Point; public class KmlExporter { public static void main(String[] args) throws FileNotFoundException, KmlException { // 创建Kml对象 Kml kml = new Kml(); // 创建Placemark对象 Placemark placemark = new Placemark(); // 设置Placemark的名称和描述 placemark.setName("My Placemark"); placemark.setDescription("This is a sample placemark"); // 创建Point对象 Point point = new Point(); // 设置点的坐标 point.setLatitude(37.42228990140251); point.setLongitude(-122.0822035425683); // 将点添加到Placemark对象 placemark.setGeometry(point); // 将Placemark添加到Kml对象 List<Placemark> placemarks = new ArrayList<Placemark>(); placemarks.add(placemark); kml.setFeature(placemarks); // 将Kml对象写入KML文件 File file = new File("sample.kml"); kml.marshal(new FileOutputStream(file)); } } ``` 在这个例子中,我们创建了一个名为"My Placemark"的Placemark对象,该对象包含一个点的坐标。然后,我们将该Placemark添加到Kml对象中,并将Kml对象写入名为"sample.kml"的文件中。你可以根据自己的需求修改代码和添加更多的Placemark对象。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值