springboot将数据库内容编译成csv样式通过FTP上传

springboot将数据库内容编译成csv样式通过FTP上传,第1张

引用的jar包

		
        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-csvartifactId>
            <version>1.8version>
        dependency>
		
        <dependency>
            <groupId>commons-netgroupId>
            <artifactId>commons-netartifactId>
        dependency>
public void test() {
        
        try {
            // 准备输出流
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(outputStream, "GBK");
            // 假如标题上还有一行文件说明信息
            CSVPrinter printer = new CSVPrinter(osw, CSVFormat.DEFAULT.withHeader("收件人",":张三","1","寄件人",":罗老师"));
            printer.printRecord("标题1","标题2","标题3","标题4","标题5","标题6","7");
            printer.printRecord("211128","20211128","11111","22222","33333","","9222");
            printer.printRecord("211128","20211128","11111","22222","33333","","9222");
            printer.flush();
            printer.close();
            ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
            FTPClient ftpClient = FtpUtil.connect();
            String fileName = "法外狂徒.csv";
            FtpUtil.upload(ftpClient,fileName,inputStream,"/test/upload");
            ftpClient.logout();
            if (ftpClient.isConnected()) {
                ftpClient.disconnect();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/741626.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-28
下一篇2022-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存