1. /*
  2. * @(#)FileWriter.java 1.17 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.io;
  8. /**
  9. * Convenience class for writing character files. The constructors of this
  10. * class assume that the default character encoding and the default byte-buffer
  11. * size are acceptable. To specify these values yourself, construct an
  12. * OutputStreamWriter on a FileOutputStream.
  13. *
  14. * <p>Whether or not a file is available or may be created depends upon the
  15. * underlying platform. Some platforms, in particular, allow a file to be
  16. * opened for writing by only one <tt>FileWriter</tt> (or other file-writing
  17. * object) at a time. In such situations the constructors in this class
  18. * will fail if the file involved is already open.
  19. *
  20. * <p><code>FileWriter</code> is meant for writing streams of characters.
  21. * For writing streams of raw bytes, consider using a
  22. * <code>FileOutputStream</code>.
  23. *
  24. * @see OutputStreamWriter
  25. * @see FileOutputStream
  26. *
  27. * @version 1.17, 03/01/23
  28. * @author Mark Reinhold
  29. * @since JDK1.1
  30. */
  31. public class FileWriter extends OutputStreamWriter {
  32. /**
  33. * Constructs a FileWriter object given a file name.
  34. *
  35. * @param fileName String The system-dependent filename.
  36. * @throws IOException if the named file exists but is a directory rather
  37. * than a regular file, does not exist but cannot be
  38. * created, or cannot be opened for any other reason
  39. */
  40. public FileWriter(String fileName) throws IOException {
  41. super(new FileOutputStream(fileName));
  42. }
  43. /**
  44. * Constructs a FileWriter object given a file name with a boolean
  45. * indicating whether or not to append the data written.
  46. *
  47. * @param fileName String The system-dependent filename.
  48. * @param append boolean if <code>true</code>, then data will be written
  49. * to the end of the file rather than the beginning.
  50. * @throws IOException if the named file exists but is a directory rather
  51. * than a regular file, does not exist but cannot be
  52. * created, or cannot be opened for any other reason
  53. */
  54. public FileWriter(String fileName, boolean append) throws IOException {
  55. super(new FileOutputStream(fileName, append));
  56. }
  57. /**
  58. * Constructs a FileWriter object given a File object.
  59. *
  60. * @param file a File object to write to.
  61. * @throws IOException if the file exists but is a directory rather than
  62. * a regular file, does not exist but cannot be created,
  63. * or cannot be opened for any other reason
  64. */
  65. public FileWriter(File file) throws IOException {
  66. super(new FileOutputStream(file));
  67. }
  68. /**
  69. * Constructs a FileWriter object given a File object. If the second
  70. * argument is <code>true</code>, then bytes will be written to the end
  71. * of the file rather than the beginning.
  72. *
  73. * @param file a File object to write to
  74. * @param append if <code>true</code>, then bytes will be written
  75. * to the end of the file rather than the beginning
  76. * @throws IOException if the file exists but is a directory rather than
  77. * a regular file, does not exist but cannot be created,
  78. * or cannot be opened for any other reason
  79. * @since 1.4
  80. */
  81. public FileWriter(File file, boolean append) throws IOException {
  82. super(new FileOutputStream(file, append));
  83. }
  84. /**
  85. * Constructs a FileWriter object associated with a file descriptor.
  86. *
  87. * @param fd FileDescriptor object to write to.
  88. */
  89. public FileWriter(FileDescriptor fd) {
  90. super(new FileOutputStream(fd));
  91. }
  92. }