Exemplo n.º 1
0
 /**
  * Constructs a new FileOutputStream on the File {@code file}. The parameter {@code append}
  * determines whether or not the file is opened and appended to or just opened and overwritten.
  *
  * @param file the file to which this stream writes.
  * @param append indicates whether or not to append to an existing file.
  * @throws FileNotFoundException if the {@code file} cannot be opened for writing.
  * @throws SecurityException if a {@code SecurityManager} is installed and it denies the write
  *     request.
  * @see java.lang.SecurityManager#checkWrite(FileDescriptor)
  * @see java.lang.SecurityManager#checkWrite(String)
  */
 public FileOutputStream(File file, boolean append) throws FileNotFoundException {
   super();
   if (file.getPath().isEmpty() || file.isDirectory()) {
     throw new FileNotFoundException(file.getAbsolutePath());
   }
   fd = new FileDescriptor();
   fd.readOnly = false;
   fd.descriptor = open(file.getAbsolutePath(), append);
 }
Exemplo n.º 2
0
 /**
  * Closes this stream. This implementation closes the underlying operating system resources
  * allocated to represent this stream.
  *
  * @throws IOException if an error occurs attempting to close this stream.
  */
 @Override
 public void close() throws IOException {
   if (fd == null) {
     // if fd is null, then the underlying file is not opened, so nothing
     // to close
     return;
   }
   synchronized (this) {
     if (fd.descriptor >= 0) {
       close(fd.descriptor);
       fd.descriptor = -1;
     }
   }
 }