FileWriter.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* FileWriter.java -- Convenience class for writing to files.
  2. Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.io;
  32. /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
  33. * "The Java Language Specification", ISBN 0-201-63451-1
  34. * Status: Complete to version 1.1.
  35. */
  36. /**
  37. * This is a convenience class for writing to files. It creates an
  38. * <code>FileOutputStream</code> and initializes an
  39. * <code>OutputStreamWriter</code> to write to it.
  40. *
  41. * @author Aaron M. Renn (arenn@urbanophile.com)
  42. * @author Tom Tromey (tromey@cygnus.com)
  43. */
  44. public class FileWriter extends OutputStreamWriter
  45. {
  46. /**
  47. * This method initializes a new <code>FileWriter</code> object to write
  48. * to the specified <code>File</code> object.
  49. *
  50. * @param file The <code>File</code> object to write to.
  51. *
  52. * @throws SecurityException If writing to this file is forbidden by the
  53. * <code>SecurityManager</code>.
  54. * @throws IOException If any other error occurs
  55. */
  56. public FileWriter(File file) throws SecurityException, IOException
  57. {
  58. super(new FileOutputStream(file));
  59. }
  60. /**
  61. * This method initializes a new <code>FileWriter</code> object to write
  62. * to the specified <code>File</code> object.
  63. *
  64. * @param file The <code>File</code> object to write to.
  65. * @param append <code>true</code> to start adding data at the end of the
  66. * file, <code>false</code> otherwise.
  67. *
  68. * @throws SecurityException If writing to this file is forbidden by the
  69. * <code>SecurityManager</code>.
  70. * @throws IOException If any other error occurs
  71. */
  72. public FileWriter(File file, boolean append) throws IOException
  73. {
  74. super(new FileOutputStream(file, append));
  75. }
  76. /**
  77. * This method initializes a new <code>FileWriter</code> object to write
  78. * to the specified <code>FileDescriptor</code> object.
  79. *
  80. * @param fd The <code>FileDescriptor</code> object to write to
  81. *
  82. * @throws SecurityException If writing to this file is forbidden by the
  83. * <code>SecurityManager</code>.
  84. */
  85. public FileWriter(FileDescriptor fd) throws SecurityException
  86. {
  87. super(new FileOutputStream(fd));
  88. }
  89. /**
  90. * This method intializes a new <code>FileWriter</code> object to
  91. * write to the
  92. * specified named file.
  93. *
  94. * @param name The name of the file to write to
  95. *
  96. * @throws SecurityException If writing to this file is forbidden by the
  97. * <code>SecurityManager</code>.
  98. * @throws IOException If any other error occurs
  99. */
  100. public FileWriter(String name) throws IOException
  101. {
  102. super(new FileOutputStream(name));
  103. }
  104. /**
  105. * This method intializes a new <code>FileWriter</code> object to
  106. * write to the
  107. * specified named file. This form of the constructor allows the caller
  108. * to determine whether data should be written starting at the beginning or
  109. * the end of the file.
  110. *
  111. * @param name The name of the file to write to
  112. * @param append <code>true</code> to start adding data at the end of the
  113. * file, <code>false</code> otherwise.
  114. *
  115. * @throws SecurityException If writing to this file is forbidden by the
  116. * <code>SecurityManager</code>.
  117. * @throws IOException If any other error occurs
  118. */
  119. public FileWriter(String name, boolean append) throws IOException
  120. {
  121. super(new FileOutputStream(name, append));
  122. }
  123. }