레이블이 File and io인 게시물을 표시합니다. 모든 게시물 표시
레이블이 File and io인 게시물을 표시합니다. 모든 게시물 표시

2009년 10월 27일 화요일

[자바 문자 입력 받기] Java Console

JDK 6.0 이상부터 추가된 클래스중에 Console이라는 클래스가 있다.
이제부터는 자바 커맨드 창에서 문자를 입력받을때,
복잡하게 stream을 구현할 필요가 없어 졌다.



package console;

import java.io.Console;

public class ConsoleTest {
public static void main(String args[]) {
Console console=System.console();
if(console!=null) {
String id=console.readLine("%s","ID:");
char[] password=console.readPassword("%s", "Password:");
if(id!=null & password!=null) {
System.out.println("ID="+id);
System.out.println("PW="+new String(password));
}
} else {
System.out.println("Console is null");
}
}
}




2009년 6월 30일 화요일

[Java File] 특정 디렉토리에 있는 파일 목록을 읽어내기




String path="C:\";
File dirFile=new File(path);
File []fileList=dirFile.listFiles();
for(File tempFile : fileList) {
  if(tempFile.isFile()) {
    String tempPath=tempFile.getParent();
    String tempFileName=tempFile.getName();
    System.out.println("Path="+tempPath);
    System.out.println("FileName="+tempFileName);
    /*** Do something withd tempPath and temp FileName ^^; ***/
  }

}



이것도 설명은 나중에...
뭐 그냥 소스 보면 설명은 필요 없지머...