FileReader is meant for reading streams of characters. * For reading streams of raw bytes, consider using a * FileInputStream. * * @see InputStreamReader * @see FileInputStream * * @version 1.16, 05/11/17 * @author Mark Reinhold * @since JDK1.1 */ public class FileReader extends InputStreamReader { /** * Creates a new FileReader, given the name of the * file to read from. * * @param fileName the name of the file to read from * @exception FileNotFoundException if the named file does not exist, * is a directory rather than a regular file, * or for some other reason cannot be opened for * reading. */ public FileReader(String fileName) throws FileNotFoundException { super(new FileInputStream(fileName)); } /** * Creates a new FileReader, given the File * to read from. * * @param file the File to read from * @exception FileNotFoundException if the file does not exist, * is a directory rather than a regular file, * or for some other reason cannot be opened for * reading. */ public FileReader(File file) throws FileNotFoundException { super(new FileInputStream(file)); } /** * Creates a new FileReader, given the * FileDescriptor to read from. * * @param fd the FileDescriptor to read from */ public FileReader(FileDescriptor fd) { super(new FileInputStream(fd)); } }
FileReader
FileInputStream
Whether or not a file is available or may be created depends upon the * underlying platform. Some platforms, in particular, allow a file to be * opened for writing by only one FileWriter (or other file-writing * object) at a time. In such situations the constructors in this class * will fail if the file involved is already open. * *
FileWriter is meant for writing streams of characters. * For writing streams of raw bytes, consider using a * FileOutputStream. * * @see OutputStreamWriter * @see FileOutputStream * * @version 1.19, 05/11/17 * @author Mark Reinhold * @since JDK1.1 */ public class FileWriter extends OutputStreamWriter { /** * Constructs a FileWriter object given a file name. * * @param fileName String The system-dependent filename. * @throws IOException if the named file exists but is a directory rather * than a regular file, does not exist but cannot be * created, or cannot be opened for any other reason */ public FileWriter(String fileName) throws IOException { super(new FileOutputStream(fileName)); } /** * Constructs a FileWriter object given a file name with a boolean * indicating whether or not to append the data written. * * @param fileName String The system-dependent filename. * @param append boolean if true, then data will be written * to the end of the file rather than the beginning. * @throws IOException if the named file exists but is a directory rather * than a regular file, does not exist but cannot be * created, or cannot be opened for any other reason */ public FileWriter(String fileName, boolean append) throws IOException { super(new FileOutputStream(fileName, append)); } /** * Constructs a FileWriter object given a File object. * * @param file a File object to write to. * @throws IOException if the file exists but is a directory rather than * a regular file, does not exist but cannot be created, * or cannot be opened for any other reason */ public FileWriter(File file) throws IOException { super(new FileOutputStream(file)); } /** * Constructs a FileWriter object given a File object. If the second * argument is true, then bytes will be written to the end * of the file rather than the beginning. * * @param file a File object to write to * @param append if true, then bytes will be written * to the end of the file rather than the beginning * @throws IOException if the file exists but is a directory rather than * a regular file, does not exist but cannot be created, * or cannot be opened for any other reason * @since 1.4 */ public FileWriter(File file, boolean append) throws IOException { super(new FileOutputStream(file, append)); } /** * Constructs a FileWriter object associated with a file descriptor. * * @param fd FileDescriptor object to write to. */ public FileWriter(FileDescriptor fd) { super(new FileOutputStream(fd)); } }
FileWriter
FileOutputStream
true