Java_Exception_IO

总述:异常是有点小调皮,有点小捣蛋,有点小可爱,有点小纠结,这样多样的性格的异常,成为我生活中最熟悉的亲切。

Provides for system input and output through data streams, serialization and the file system.

EOFException
Signals that an end of file or end of stream has been reached unexpectedly during input.

读到末尾异

FileNotFoundException
Signals that an attempt to open the file denoted by a specified pathname has failed.

文件未找到异常

InterruptedIOException
Signals that an I/O operation has been interrupted.

输出或输入中断异

IOException
Signals that an I/O exception of some sort has occurred.

输入输出的时候出现异

NotSerializableException
Thrown when an instance is required to have a Serializable interface.

没有序列号异

SyncFailedException
Signals that a sync operation has failed.

同步失败异

异常一般有两种方法,一种抛出,一种try/catch/finally抓住,finally一般用在close

import java.io.FileInputStream;
import java.io.IOException;

/**
 * JDK1.7之后退出了一个新的特性:自动关闭
 * @author soft01
 *
 */
public class FinallyDemo0306 {
	public static void main(String[] args) {
		
		try(
				/*
				 * AutoCloseable按接口的子类可以定义在这里
				 * 
				 * 自动关闭语法时编译期认可,变以后的class
				 * 文件中流的关闭还是在finally中进行的
				 */
				FileInputStream fis = new FileInputStream("fos.txt");
		) {
			int d = fis.read();
			System.out.println(d);
		}catch(IOException e) {
			
		}
	}
}

还有一种ERROR系统异常,不会解决

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页