Java实现将内容写到文件里面

目录

1 实现

String   appendLog = "";
	File logFile = new File(logFileName);


// append file content
		FileOutputStream fos = null;
		try {
    
    
			fos = new FileOutputStream(logFile, true);
			fos.write(appendLog.getBytes("utf-8"));
			fos.flush();
		} catch (Exception e) {
    
    
			logger.error(e.getMessage(), e);
		} finally {
    
    
			if (fos != null) {
    
    
				try {
    
    
					fos.close();
				} catch (IOException e) {
    
    
					logger.error(e.getMessage(), e);
				}
			}
		}

猜你喜欢

转载自blog.csdn.net/python113/article/details/132412792