JAVA Programming

[78] 파일 넣기 , FileInputStream fis = new FileInputStream(fileName);

꾸준히개발하자 2020. 7. 21. 08:49

FileInputStream fis = new FileInputStream("a.txt"); // 파일 읽어오기 없을시 FileNotFoundException 예외처리 

Class c = Class.forName(className);  클래스 동적 할당  읽어오기 ClassNotFoundException 예외처리

FileNotFoundException, ClassNotFoundException

 

FileInputStream fis = null;
		
		try {
			fis = new FileInputStream("a.txt");  // 파일을 읽어들인다. // 파일이 없을수 있어서 FileNotFoundException 이 발생 
		} catch (FileNotFoundException e) {
			System.out.println(e); // 지정된 파일을 찾을수없다고 나온다.
			return; // 파일이 있으면 밑에까지 다수행 없으면 리턴 종료하고 finally 수행  
		} finally { // finally 은 무조건 실행된다.