/**
* 写入文件
*
* @param sb
* @param fileName
*/
public static void saveToText(StringBuffer sb, String fileName) {
if (sb == null || fileName == null) {
return;
}
File batFile = new File(fileName);
if (!batFile.exists()) {
try {
batFile.createNewFile();
} catch (IOException e) {
Log.getlogger().error("创建文件失败,路径:" + fileName);
Log.exception(e);
return;
}
}
FileOutputStream fos = null;
PrintWriter pw = null;
try {
fos = new FileOutputStream(batFile);
pw = new PrintWriter(fos);
pw.write(sb.toString());
} catch (FileNotFoundException e) {
Log.getlogger().error("写文件失败,路径:" + fileName);
Log.exception(e);
return;
} finally {
if (pw != null) {
pw.flush();
pw.close();
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
Log.getlogger().error("写文件关闭流失败,路径:" + fileName);
Log.exception(e);
return;
}
}
}
}
* 写入文件
*
* @param sb
* @param fileName
*/
public static void saveToText(StringBuffer sb, String fileName) {
if (sb == null || fileName == null) {
return;
}
File batFile = new File(fileName);
if (!batFile.exists()) {
try {
batFile.createNewFile();
} catch (IOException e) {
Log.getlogger().error("创建文件失败,路径:" + fileName);
Log.exception(e);
return;
}
}
FileOutputStream fos = null;
PrintWriter pw = null;
try {
fos = new FileOutputStream(batFile);
pw = new PrintWriter(fos);
pw.write(sb.toString());
} catch (FileNotFoundException e) {
Log.getlogger().error("写文件失败,路径:" + fileName);
Log.exception(e);
return;
} finally {
if (pw != null) {
pw.flush();
pw.close();
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
Log.getlogger().error("写文件关闭流失败,路径:" + fileName);
Log.exception(e);
return;
}
}
}
}