자바 의 Closeable 인터페이스 close () 방법의 의미

1183 단어 Java
Closeable 인 터 페 이 스 는 또 다른 부모 인 터 페 이 스 를 계승 했다. AutoCloseable
그 중에서 close () 방법 은 흐름 을 닫 고 그 와 관련 된 모든 방법 을 방출 하 는 것 입 니 다. 흐름 이 닫 혔 다 면 이 방법 을 사용 하 는 것 은 효과 가 없습니다.
InputStream 과 OutputStream 류 는 모두 이 인 터 페 이 스 를 실현 했다.
원본 코드:
package java.io;

import java.io.IOException;

/**
 * A {@code Closeable} is a source or destination of data that can be closed.
 * The close method is invoked to release resources that the object is
 * holding (such as open files).
 *
 * @since 1.5
 */
public interface Closeable extends AutoCloseable {

    /**
     * Closes this stream and releases any system resources associated
     * with it. If the stream is already closed then invoking this
     * method has no effect.
     *
     * 

As noted in {@link AutoCloseable#close()}, cases where the * close may fail require careful attention. It is strongly advised * to relinquish the underlying resources and to internally * mark the {@code Closeable} as closed, prior to throwing * the {@code IOException}. * * @throws IOException if an I/O error occurs */ public void close() throws IOException; }


좋은 웹페이지 즐겨찾기