java导出csv文件
时间: 2023-05-21 12:06:35 浏览: 238
对于java导出csv文件,可以使用以下代码来实现:
```java
import java.io.*;
import java.util.List;
public class CsvExporter {
public void exportCsv(List<String[]> data, String filePath) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(filePath), "UTF-8"))) {
for (String[] row : data) {
StringBuilder sb = new StringBuilder();
for (String cell : row) {
sb.append(cell).append(",");
}
sb.setLength(sb.length() - 1);
writer.write(sb.toString());
writer.newLine();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
其中,List<String[]> data表示待导出的数据,filePath表示导出的文件路径。这个代码片段可以将数据导出为csv格式的文件。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)