본문 바로가기

프로그래밍/Java

File API

 

package ex11_5;

 

import java.io.File;                  // File 불러오기

 

public class Ex11_5 {
    public static void main(String[] args) {
        try{        
        File f = new File("D:\\temp","Ex11_5.java");       

        System.out.println(f.getName());                   

        System.out.println(f.exists());                    

        System.out.println(f.getPath());                   

        System.out.println(f.length());                    

        System.out.println(File.separator);                

        boolean a = new File("D:\\temp\\ccc").mkdir();    

        boolean b = new File("D:\\temp","1.txt").delete(); 
        String [] listing = new File("D:\\temp").list();
                
        for (int i = 0; i < listing.length; i++){
            System.out.println("temp 폴더 내용 : "+listing[i] );
        }
        }   catch(Exception e){e.printStackTrace();}     
    }
}

 

 

// File 객체 생성 안에 값은

(파일 경로,파일명지정)

 

// 지정한 파일명 출력

 

// exists()는 boolean형이기 떄문에

파일 존재시 true 없을시 false

 

// 지정한 파일의 경로를 출력한다.

 

// 파일의 크기를 츨력한다.

// 현재 파일의 구분자를 출력

 

// D:\\temp\\ccc 이쪽경로에

  mkdir 폴더를 생성해준다

 

// D:\\temp","1.txt" 1.txt파일을 삭제

       
// list() 추상 경로명이 가리키는 디렉토리에 있는 파일 및 디렉토리를 캐릭터 라인 배열을 돌려줍니다



 

 

그림

'프로그래밍 > Java' 카테고리의 다른 글

Thread 구현하기  (0) 2012.06.19
Thread 스레드  (0) 2012.06.19
다형성을 메소드 인자  (0) 2012.06.18
인터페이스 ( interface )  (0) 2012.06.18
super 실습하기  (0) 2012.06.18