/**
     * 파일 복사
     * @param sourceName
     * @param targetName
     * @throws Exception
     */
    private void fileCopy(String sourceName, String targetName) throws Exception  {
       
        InputStream inputStream = null;
        FileOutputStream fileOutputStream = null;
       
        try {
            inputStream = new FileInputStream(new File(sourceName));
            fileOutputStream = new FileOutputStream(new File(targetName));
           
            int data = 0;
            while ((data = inputStream.read()) != -1) {
                fileOutputStream.write(data);
            }
            fileOutputStream.close();
            inputStream.close();
        } catch(Exception e) {
            throw e;
        } finally {
            if(fileOutputStream != null) { try { fileOutputStream.close(); } catch(Exception ex) {} }
            if(inputStream != null) { try { inputStream.close(); } catch(Exception ex) {} }
        }
       
    }
   
    /**
     * 파일 목록
     * @param fileName
     * @return
     * @throws Exception
     */
    private List<String> getFileList(String fileName) throws Exception {
        List<String> list = new ArrayList<String>();
        File file = new File(fileName);
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(file));
            String line = null;
            while( (line = br.readLine()) != null) {
                list.add(line);
            }
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            if(br != null) try { br.close(); } catch(Exception e) {}
        }
        return list;
    }
   
    /**
     * 디렉토리 및 파일 삭제
     * @param name
     * @throws Exception
     */
    private void deleteFile(String name) throws Exception {
        File inputFile = new File(name);
        if(inputFile.exists()) {
            if(inputFile.isDirectory()) {
                // 디렉토리이면 하위 파일 및 폴더를 삭제하고, 자신을 삭제
                File[] fileList = inputFile.listFiles();
                if(fileList != null && fileList.length > 0) {
                    for(File file : fileList) {
                        if(file.isDirectory()) deleteFile(file.getAbsolutePath());
                        else file.delete();
                    }
                }
            }
            inputFile.delete();
        }
    }

'java' 카테고리의 다른 글

Java DBCP(DataBase Connection Pool) 사용  (0) 2014.11.13
Linux 에서 실행하는 기본 명령들  (0) 2014.11.06
JWT(JSON Web Token)  (0) 2014.10.17
PMD로 배우는 올바른 자바 코딩 방법  (0) 2014.09.16
비밀번호 암호화 SHA256, Salt  (0) 2014.08.07
Posted by gt1000

블로그 이미지
gt1000

태그목록

공지사항

어제
오늘

달력

 « |  » 2024.3
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함