code: private void openFile(final File log) throws IOException
     {
        SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
        {
           @SuppressWarnings("resource")
           public Void run() throws Exception
           {
              // set file size;
              if (!log.exists())
              {
                 log.getParentFile().mkdirs();
                 log.createNewFile();
                 out = new FileOutputStream(log).getChannel();
                 out.position(1024 * fileSize - 1);
                 out.write(ByteBuffer.wrap(new byte[]{0}));
                 out.position(0);
                 out.force(false);
              }
              else
              {
                 out = new FileOutputStream(log, true).getChannel();
              }
              return null;
           }
        });
     }
docs: openFile.
  
  @param log
  @throws IOException