1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package java.io; 19 20/** 21 * A specialized {@link Reader} that reads from a file in the file system. 22 * All read requests made by calling methods in this class are directly 23 * forwarded to the equivalent function of the underlying operating system. 24 * Since this may induce some performance penalty, in particular if many small 25 * read requests are made, a FileReader is often wrapped by a 26 * BufferedReader. 27 * 28 * @see BufferedReader 29 * @see FileWriter 30 */ 31public class FileReader extends InputStreamReader { 32 33 /** 34 * Constructs a new FileReader on the given {@code file}. 35 * 36 * @param file 37 * a File to be opened for reading characters from. 38 * @throws FileNotFoundException 39 * if {@code file} does not exist. 40 */ 41 public FileReader(File file) throws FileNotFoundException { 42 super(new FileInputStream(file)); 43 } 44 45 /** 46 * Construct a new FileReader on the given FileDescriptor {@code fd}. Since 47 * a previously opened FileDescriptor is passed as an argument, no 48 * FileNotFoundException can be thrown. 49 * 50 * @param fd 51 * the previously opened file descriptor. 52 */ 53 public FileReader(FileDescriptor fd) { 54 super(new FileInputStream(fd)); 55 } 56 57 /** 58 * Construct a new FileReader on the given file named {@code filename}. 59 * 60 * @param filename 61 * an absolute or relative path specifying the file to open. 62 * @throws FileNotFoundException 63 * if there is no file named {@code filename}. 64 */ 65 public FileReader(String filename) throws FileNotFoundException { 66 super(new FileInputStream(filename)); 67 } 68} 69