filechecks.java

来自「基于LWVCL开发的库」· Java 代码 · 共 77 行

JAVA
77
字号
import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileNotFoundException;public class FileChecks {	public static void main(String[] argv) 	{		try		{			new FileInputStream(".");			System.out.println("1 FAIL! Should throw java.io.FileNotFoundException!");			System.exit(1);		}		catch (FileNotFoundException e)		{			System.out.println("1 Success.");		}		try		{			File                file = new File(".");			new FileInputStream(file);			System.out.println("2 FAIL! Should throw java.io.FileNotFoundException!");			System.exit(1);		}		catch (FileNotFoundException e)		{			System.out.println("2 Success.");		}		try		{			new FileOutputStream(".");			System.out.println("3 FAIL! Should throw java.io.FileNotFoundException!");			System.exit(1);		}		catch (FileNotFoundException e)		{			System.out.println("3 Success.");		}		try		{			File                file = new File(".");			new FileOutputStream(file);			System.out.println("4 FAIL! Should throw java.io.FileNotFoundException!");			System.exit(1);		}		catch (FileNotFoundException e)		{			System.out.println("4 Success.");		}		try		{			File                file = new File("FileChecks.class"); // should exist			new FileInputStream(file);			System.out.println("5 Success.");		}		catch (FileNotFoundException e)		{			System.out.println("5 FAIL! Should not get: " +e);		}	}}/* Expected Output:1 Success.2 Success.3 Success.4 Success.5 Success.*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?