1 // FileOutputStream.java - Write bytes to a file.
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
14 * @author Tom Tromey <tromey@cygnus.com>
15 * @date September 24, 1998
18 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
19 * "The Java Language Specification", ISBN 0-201-63451-1
20 * Status: Complete to version 1.1.
23 public class FileOutputStream extends OutputStream
25 public FileOutputStream (String path, boolean append)
26 throws SecurityException, IOException
28 SecurityManager s = System.getSecurityManager();
31 fd = new FileDescriptor (path, (append
32 ? FileDescriptor.APPEND
33 : FileDescriptor.WRITE));
36 public FileOutputStream (String path) throws SecurityException, IOException
41 public FileOutputStream (File file) throws SecurityException, IOException
43 this (file.getPath(), false);
46 public FileOutputStream (FileDescriptor fdObj) throws SecurityException
48 SecurityManager s = System.getSecurityManager();
54 protected void finalize () throws IOException
56 // We don't actually need this, but we include it because it is
57 // mentioned in the JCL.
60 public final FileDescriptor getFD () throws IOException
63 throw new IOException ();
67 public void write (int b) throws IOException
72 public void write (byte[] b) throws IOException, NullPointerException
74 fd.write (b, 0, b.length);
77 public void write (byte[] b, int off, int len)
78 throws IOException, NullPointerException, IndexOutOfBoundsException
80 if (off < 0 || len < 0 || off + len > b.length)
81 throw new ArrayIndexOutOfBoundsException ();
82 fd.write (b, off, len);
85 public void close () throws IOException
91 // Instance variables.
92 private FileDescriptor fd;