Path: blob/master/src/java.base/share/classes/java/io/FileNotFoundException.java
41152 views
/*1* Copyright (c) 1994, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.io;262728/**29* Signals that an attempt to open the file denoted by a specified pathname30* has failed.31*32* <p> This exception will be thrown by the {@link FileInputStream}, {@link33* FileOutputStream}, and {@link RandomAccessFile} constructors when a file34* with the specified pathname does not exist. It will also be thrown by these35* constructors if the file does exist but for some reason is inaccessible, for36* example when an attempt is made to open a read-only file for writing.37*38* @since 1.039*/4041public class FileNotFoundException extends IOException {42@java.io.Serial43private static final long serialVersionUID = -897856973823710492L;4445/**46* Constructs a {@code FileNotFoundException} with47* {@code null} as its error detail message.48*/49public FileNotFoundException() {50super();51}5253/**54* Constructs a {@code FileNotFoundException} with the55* specified detail message. The string {@code s} can be56* retrieved later by the57* {@link java.lang.Throwable#getMessage}58* method of class {@code java.lang.Throwable}.59*60* @param s the detail message.61*/62public FileNotFoundException(String s) {63super(s);64}6566/**67* Constructs a {@code FileNotFoundException} with a detail message68* consisting of the given pathname string followed by the given reason69* string. If the {@code reason} argument is {@code null} then70* it will be omitted. This private constructor is invoked only by native71* I/O methods.72*73* @since 1.274*/75private FileNotFoundException(String path, String reason) {76super(path + ((reason == null)77? ""78: " (" + reason + ")"));79}8081}828384