Closeable
是 Java 中的一个接口,位于 java.io 包中。它定义了一个单一的方法 close()
,用于关闭资源,如文件、套接字或其他需要显式关闭的资源。实现了 Closeable
接口的类通常表示一种可以关闭的资源,以确保资源被及时释放。
public interface Closeable extends AutoCloseable {
void close() throws IOException;
}
Closeable
接口继承了 AutoCloseable
接口,这意味着可以在 Java 7 及更高版本中使用 try-with-resources