import java io import java util class File

  • Slides: 19
Download presentation

자바 입출력 import java. io. *; import java. util. *; class File. Exam {

자바 입출력 import java. io. *; import java. util. *; class File. Exam { public static void main(String args[]) { File dir = new File("c: \test"); File file = new File(dir, “test. txt"); if(dir. is. Directory()) { System. out. println("File 클래스 객체 dir은 디렉토리입니다. "); String files[] = dir. list(); System. out. println("디렉토리의 파일 목록 : "); for(int index=0; index < files. length; index++) { System. out. println(" "+files[index]); } } System. out. println("상위 디렉토리 : " + dir. get. Parent()); System. out. println("디렉토리의 이름 : " + dir. get. Name()); System. out. println("디렉토리의 경로 : " + dir. get. Path()); if(file. is. File()) { System. out. println("File 클래스 객체 file은 파일입니다. "); System. out. println("마지막 수정시간 : "+ new Date(file. last. Modified())); System. out. println("파일의 크기 "+ file. length() + "byte"); } System. out. println("상위 디렉토리 : " + file. get. Parent()); System. out. println("파일의 이름 : " + file. get. Name()); System. out. println("파일의 경로 : " + file. get. Path()); } } 5

자바 입출력 n 예제 import java. io. *; public class Char. Stream. Exam {

자바 입출력 n 예제 import java. io. *; public class Char. Stream. Exam { public static void main(String args[]) { try { File. Reader fr = new File. Reader(new File("c: \test\file. txt Buffered. Reader br = new Buffered. Reader(fr); String line = null; while((line=br. read. Line())!= null) { System. out. println(line); } }catch(IOException ioe) {} } } 9

자바 입출력 n 예제 import java. io. *; public class Byte. Stream. Exam {

자바 입출력 n 예제 import java. io. *; public class Byte. Stream. Exam { public static void main(String args[]) { try { Buffered. Input. Stream bis = new Buffered. Input. Stream(System. in); Buffered. Output. Stream bos = new Buffered. Output. Stream(System. out); byte buf[] = new byte[64]; int len = 0; bos. write("문자열을 입렵하세요 : n". get. Bytes()); bos. flush(); while((len=bis. read(buf))!= -1) { bos. write(buf, 0, len); bos. flush(); } bis. close(); bos. close(); }catch(Exception e) {} } } 11

자바 입출력 n 예제 { class Final. Exam // 클래스 외부에서 바로 접근할 수

자바 입출력 n 예제 { class Final. Exam // 클래스 외부에서 바로 접근할 수 있는 멤버를 final로 설정하면 클래스 외부에서 값을 변경할 수 없다. public static final String class. Name = "Final. Exam"; private final int MAX_SIZE = 10; private int[] array = new int[MAX_SIZE]; //final로 선언된 메서드인 get. Array. Size()는 Final. Exam을 상속받은 Final. Class. Exam 클래스에 서 오버라이딩 할 수 없다. public final int get. Array. Size() { return array. length; } } // Final. Class. Exam 클래스를 상속받는 클래스를 구현할 수 없다. public final class Final. Class. Exam extends Final. Exam { public static void main(String args[]) { Final. Exam final. Exam = new Final. Class. Exam(); System. out. println("클래스 이름 : " + Final. Exam. class. Name); System. out. println("배열의 크기 : " + final. Exam. get. Array. Size()); } } 19