package com.file;//

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileEx4 {
	public static void main(String[] args) {

		String currDir = System.getProperty("user.dir");
		File dir = new File(currDir);

		File[] files = dir.listFiles();

		for(int i=0; i<files.length;i++){
			File f= files[i];
			String name = f.getName();//디렉토리명 또는 파일명
			SimpleDateFormat df =new SimpleDateFormat("yyyy-MM-DD HH:mma");
			String attribute = "";
			String size="";

			if(files[i].isDirectory()){
				attribute = "DIR";
			}else{
				size = f.length()+""; //형변환 long -> String
				attribute = f.canRead() ? "R" : " ";
				attribute = f.canWrite() ? "W" : " ";
				attribute = f.isHidden() ? "H" : " ";
			}

			System.out.printf("%s %3s %6s %s\n",df.format
					(new Date(f.lastModified())),attribute,size,name);

		}
	}
}


'Java > 입출력' 카테고리의 다른 글

직렬화  (0) 2012.04.13
File 생성 및 변경  (0) 2012.04.13
디렉토리 정보  (0) 2012.04.13
입출력으로 파일 상세정보  (0) 2012.04.13
키보드에서 입력받은 내용을 파일에 기록하기  (0) 2012.04.13

+ Recent posts