将需要书写的内容,以追加的方式写到文件中

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hzk594512323/article/details/47017327
public void writeScriptLog(String writeInfo,Boolean isError) {
File folder =new File("目录");
try {
if (!folder.exists()) {
folder.mkdirs();
}
File logFile =new File("目录/文件");
if (!logFile.exists()) {
logFile.createNewFile();
}
FileOutputStream fos = null;
OutputStreamWriter osw =null;
fos = new FileOutputStream(logFile.getPath(), true);  
osw = new OutputStreamWriter(fos);
String data=new SimpleDateFormat("MM/dd HH:mm:ss").format(new Date());
if (!isError) {
osw.write(data+" Info:"+writeInfo+ System.getProperty("line.separator"));
}else {
osw.write(data+" Error:"+writeInfo+ System.getProperty("line.separator"));
}
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
}

猜你喜欢

转载自blog.csdn.net/hzk594512323/article/details/47017327
今日推荐