Code example for RandomAccessFile

Methods: close, length, seek, write

0
	 */ 
	public static void addContentToFile(File file,String content,boolean addFlag) throws UtilException{
		 try { 
			  // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss "); 
			  // String contents = sdf.format(new Date()) + content + "\r\n"; 
			   RandomAccessFile raf = new RandomAccessFile(file, "rw");
			   if(addFlag){
				   raf.seek(raf.length());
			   }else{ 
				   raf.seek(0);
			   } 
			   raf.write(content.getBytes("UTF-8"));
			   raf.close();
			  } catch (FileNotFoundException e) {
				  throw new UtilException(e);
			  } catch (IOException e) {
				  throw new UtilException(e);
			  } 
	} 
}