Java中IO写文件工具类(二)

2014-11-23 22:10:03 · 作者: · 浏览: 49

File file = new File(filePath);

if(!file.exists()){
boolean tempFlag = file.mkdirs();
if(!tempFlag){
log.error("文件夹"+filePath+"创建失败");
return;
}
}

file = new File(filePath,filename);


if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(filePath+filename, flag);
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
for (String temp : fileContent)
osw.write(temp + "\r\n");
osw.flush();
osw.close();
}


--------------------------------------分割线 --------------------------------------


--------------------------------------分割线 --------------------------------------