반응형

재귀 함수를 이용해 한번에 File[]에 모든 파일들을 넣는 방법도 있지만

난 좀 더 쉽게 파일을 찾아 디렉토리면 다시 폴더로 들어가고 아니면 파일을 여는 재귀함수 방법으로 구현하였다.

public static void test(File f){

File f = new File("파일(폴더) 경로");

if(f.isDirectory()){        //f가 디렉토리인지 확인

File []arrFS=f.listFiles();        //디렉토리이니까 파일 리스트를 받아온다.

for(int i = 0 ; i<arrFS.length;i++){        //파일 수 만큼 함수 다시 실행.

test(arrFS[i]);

}

}

else{

 //do somethings

}

}

이렇게 구현하면 매우 쉽게 폴더안의 내용들을 읽어 올 수 있다.

반응형
반응형

CentOs에 root외 ssh접속 유저 계정을 만드는 방법

Centos 6.7 (Final) version


생성 방법

1.  useradd [options] LOGIN

   ex) useradd black  -> black이라는 유저 생성

         ID에 생성할 유저 ID를 넣으면 된다.

         /home/ 폴더에 유저 폴더 생성이 된다.

options :

     -b, --base-dir BASE_DIR                          base directory for the home directory of the new account

     -c, --comment COMMENT                      GECOS field of the new account

     -d, --home-dir HOME_DIR                       home directory of the new account

     -D, --defaults                                             print or change default useradd configuration

     -e, --expiredate EXPIRE_DATE                 expiration date of the new account

     -f, --inactive INACTIVE                               password inactivity period of the new account

     -g, --gid GROUP                                          name or ID of the primary group of the new account

     -G, --groups GROUPS                                list of supplementary groups of the new account

     -h, --help                                                    display this help message and exit

     -k, --skel SKEL_DIR                                   use this alternative skeleton directory

     -K, --key KEY=VALUE                                override /etc/login.defs defaults

     -l, --no-log-init                                          do not add the user to the lastlog and faillog databases

     -m, --create-home                                   create the user's home directory

     -M, --no-create-home                              do not create the user's home directory

     -N, --no-user-group                                 do not create a group with the same name as the user

     -o, --non-unique                                      allow to create users with duplicate (non-unique) UID

     -p, --password PASSWORD                    encrypted password of the new account

     -r, --system                                               create a system account

     -s, --shell SHELL                                       login shell of the new account

     -u, --uid UID                                             user ID of the new account

     -U, --user-group                                       create a group with the same name as the user

     -Z, --selinux-user SEUSER                        use a specific SEUSER for the SELinux user mapping

2. passwd ID

    ex) passwd black -> black 유저 비밀번호 설정.

         생성한 유저 ID의 비밀번호를 설정한다.

         비밀번호가 짧고 숫자나 문자로만 되어있으면

         잘못된 암호: 너무 짧습니다  

         잘못된 암호: 너무 간단함

         라는 메세지가 출력되지만 무시하고 설정하면 비밀번호 설정이 된다.(비추)

삭제 방법

1. userdel [options] LOGIN

    ex) userdel black -> black 유저 삭제

          /home/경로에 생성된 유저 폴더는 삭제가 안된다.

options :

     -f, --force                                           force removal of files, even if not owned by user

     -h, --help                                           display this help message and exit

     -r, --remove                                      remove home directory and mail spool

     -Z, --selinux-user                              remove SELinux user from SELinux user mapping

반응형

'Linux > CentOs' 카테고리의 다른 글

CentOS 버전 확인  (0) 2016.01.18
반응형

평상시에는 LayoutManager를 이용하여 UI의 위치를 잡고 사용하지만

가끔 setbounds을 이용해 UI 위치를 절대값을 사용하여 위치하는 경우가 있다.

이 함수를 사용하면 편하게 원하는 위치에 UI위치를 설정할 수 있다.

하지만 이 함수를 쓰면 위치와 크기가 고정이 되어 프로그램 크기를 조정했을때 변하지 않고 항상 그 위치에 고정되어있다.

이 상태를 해결하기위해 JAVA는 ComponentListener라는 리스너를 지원해준다.

이 리스너에서 사용할 수 있는 함수는 4가지가 있다.

void componentHidden (ComponentEvent e) 
컴퍼넌트가 불가시가 되면(자) 불려 갑니다.
void componentMoved (ComponentEvent e) 
컴퍼넌트의 위치가 바뀌면(자) 불려 갑니다.
void componentResized (ComponentEvent e) 
컴퍼넌트의 사이즈가 바뀌면(자) 불려 갑니다.
void componentShown (ComponentEvent e) 
컴퍼넌트가 가시가 되면(자) 불려 갑니다.

저 함수들 중 componentResized() 함수를 이용하여 컴포넌트 크기가 변할 때 setbounds를 다시 실행시켜주면

 setbounds를 이용한 자신만의 LayoutManager를 사용한 것과 같은 효과를 낼 수 있다.

반응형

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

[팁] application bundle 위치  (0) 2015.12.08
JAVA L&F(Look & Feel)  (0) 2015.12.05
Java 폴더안에 내용 모두 읽기  (4) 2015.12.03
JAVA Jtable cell not editable  (0) 2015.12.02
JAVA Jtable 자동 키입력 막기  (0) 2015.12.02

+ Recent posts