java
Stream 5.1(파일목록출력하기)
바이홍
2007. 4. 18. 12:15
반응형
▶파일 목록 출력하기
☆작업 디렉토리에 대한 정보를 알고자 한다면 파일객체를 생성하면 된다
☆현재디렉토리의 파일객체생성
ex)File f=new File(".");
☆상위 디렉토리의 파일객체생성
ex)File f=new File("..")
import java.io.*;
public class SystemInMain {
public static void main(String args[]) throws IOException{
File f=new File("."); //현재 디렉토리의 파일 객체 생성
File f1=new File(".."); //상위 디렉토리의 파일 객체 생성
System.out.println("AbsolutePath"); //절대경로
System.out.println("Current f : "+f.getAbsolutePath());
System.out.println("Current f1 : "+f1.getAbsolutePath());
System.out.println("CanonicalPath"); //일반경로
System.out.println("Current f : "+f.getCanonicalPath());
System.out.println("Current f1 : "+f1.getCanonicalPath());
//절대경로를 이요한 파일 객체 생
File f3=new File("c:\");
System.out.println("c:\ : "+f3.getAbsolutePath());
}
}
☆작업 디렉토리에 대한 정보를 알고자 한다면 파일객체를 생성하면 된다
☆현재디렉토리의 파일객체생성
ex)File f=new File(".");
☆상위 디렉토리의 파일객체생성
ex)File f=new File("..")
import java.io.*;
public class SystemInMain {
public static void main(String args[]) throws IOException{
File f=new File("."); //현재 디렉토리의 파일 객체 생성
File f1=new File(".."); //상위 디렉토리의 파일 객체 생성
System.out.println("AbsolutePath"); //절대경로
System.out.println("Current f : "+f.getAbsolutePath());
System.out.println("Current f1 : "+f1.getAbsolutePath());
System.out.println("CanonicalPath"); //일반경로
System.out.println("Current f : "+f.getCanonicalPath());
System.out.println("Current f1 : "+f1.getCanonicalPath());
//절대경로를 이요한 파일 객체 생
File f3=new File("c:\");
System.out.println("c:\ : "+f3.getAbsolutePath());
}
}
