String filePath="/abc/";
File file = new File(filePath + "abd.csv");
//创建目录
File fileParent = file.getParentFile();
if (!fileParent.exists()) {
fileParent.mkdirs();
}
//删除并创建新文件
if(file.exists()){
file.delete();
}
file.createNewFile();
FileOutputStream out=null;
OutputStreamWriter osw=null;
BufferedWriter bw=null;
try {
out = new FileOutputStream(file);
osw = new OutputStreamWriter(out,"UTF-8");
bw =new BufferedWriter(osw);
//写入数据
bw.append("000").append("#");
//换行符
bw.append("\r");
} catch (Exception e) {
}finally{
if(bw!=null){
try {
bw.close();
bw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(osw!&
java 创建csv文件并写入文字
最新推荐文章于 2024-10-11 17:08:53 发布
本文介绍如何利用Java编程创建CSV文件,并将文本数据写入其中。通过示例代码,展示了如何使用BufferedWriter和逗号作为字段分隔符来实现这一过程。

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



