引用的jar包
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</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();
}
}
|