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);
}
}
}