• Programming by 白影를 방문하신 여러분을 환영합니다 :)

반올림 : Math.round

제곱함수 : Math.pow 


FIle Copy 방식

Programming/Java / Flex 白影 2015. 1. 8. 22:20

출처  : http://examples.javacodegeeks.com/core-java/io/file/4-ways-to-copy-file-in-java/


1. Copy File Using FileStreams

This is the most classic way to copy the content of a file to another. You simply read a number of bytes from File A using FileInputStream and write them to File B using FileOutputStream.

Here is the code of the first method:

01private static void copyFileUsingFileStreams(File source, File dest)
02        throws IOException {
03    InputStream input = null;
04    OutputStream output = null;
05    try {
06        input = new FileInputStream(source);
07        output = new FileOutputStream(dest);
08        byte[] buf = new byte[1024];
09        int bytesRead;
10        while ((bytesRead = input.read(buf)) > 0) {
11            output.write(buf, 0, bytesRead);
12        }
13    } finally {
14        input.close();
15        output.close();
16    }
17}

As you can see we perform several read and write operations on big chucks of data, so this ought to be a less efficient compared to the next methods we will see.

2. Copy File using java.nio.channels.FileChannel

Java NIO includes a transferFrom method that according to the documentation is supposed to do faster copying operations than FileStreams.

Here is the code of the second method:

01private static void copyFileUsingFileChannels(File source, File dest)
02        throws IOException {
03    FileChannel inputChannel = null;
04    FileChannel outputChannel = null;
05    try {
06        inputChannel = new FileInputStream(source).getChannel();
07        outputChannel = new FileOutputStream(dest).getChannel();
08        outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
09    } finally {
10        inputChannel.close();
11        outputChannel.close();
12    }
13}

3. Copy File using Apache Commons IO

Apache Commons IO offers a copyFile(File srcFile, File destFile) method in its FileUtils class that can be used to copy a file to another. It’s very convenient to work with Apache Commons FileUtils class when you already using it to your project. Basically, this class uses Java NIO FileChannel internally.

Here is the code of the third method:

1private static void copyFileUsingApacheCommonsIO(File source, File dest)
2        throws IOException {
3    FileUtils.copyFile(source, dest);
4}

4. Copy File using Java 7 Files class

If you have some experience in Java 7 you will probably know that you can use the copy mehtod of the class Files in order to copy a file to another.

Here is the code of the fourth method:

1private static void copyFileUsingJava7Files(File source, File dest)
2        throws IOException {
3    Files.copy(source.toPath(), dest.toPath());
4}


[Flex] Popup창에서 부모창으로 데이터 호출하기


검색을 해보다보니 생각보다 잘 적용하기가 쉽지 않아서 새로 정리를 함..


팝업창의 grid에서 선택한 내용의 item_name 항목을 부모창의 textinput창에 텍스트로 넣어주기 위해 팝업을 호출하는 부분에 다음과 같이 추가해준다.


부모창

pop.targetComponent = textinput;

pop.grid.selectedItem.item_name = textinput.text;


팝업창에서 해당 내용을 선택하고 넘기기 위한 이벤트 부분에 다음과 같이 추가한다.


팝업창

targetComponent.text = String(grid.selectedItem.item_name);



그러면 팝업창의 grid에서 선택한 항목의 item_name을 부모창의 textinput로 호출하여 입력해준다.


부모창 [textinput] << 팝업창 [grid.selecteditem]


원소스는 커스텀된 기능이 들어가있어서 해당 항목만 기재하였다.

'Programming > Java / Flex' 카테고리의 다른 글

숫자 반올림, 제곱함수  (0) 2015.01.08
FIle Copy 방식  (0) 2015.01.08
[Eclipse] 단축키  (0) 2013.05.28
[Flex] Datagrid / Arraycollection addItem(At)  (0) 2013.05.05
PowerJava [2판] Theory Chaper 06 반복문  (0) 2013.01.29

[Eclipse] 단축키

Programming/Java / Flex 白影 2013. 5. 28. 17:31

===== 에디터 변환 =====
1. 에디터가 여러 파일을 열어서 작업중일때 Ctrl + F6 키를 누르면 여러파일명이 나오고 F6키를 계속 누르면 아래로
2. Ctrl + Shift + F6 키를 누르면 위로 커서가 움직인다.
3. Ctrl + F7 : 뷰간 전환
4. Ctrl + F8 : 퍼스펙티브간 전환
5. F12 : 에디터로 포커스 위치

 

===== JAVA Doc 생성 =====
1. 프로젝트 -> Javadoc 생성

 

===== 내보내기 =====
해당 프로젝트를 zip 행태로 압축해서 보관할 수 있다.

 

===== 자바 찾아보기 perspective =====
해당 프로젝트를 보다 편리하게 한번 둘러보는데 좋다.

 

===== 스크랩북 =====
1. 스크랩북을 이용하면 자바파일을 만들어 테스트 해보지 않고도 간단하게 테스트 해 볼 수 있다.
2. 패키지 탐색기에서 신규 -> 기타 -> 자바 -> 자바 실행/디버그 -> 스크랩북 페이지 선택

 

===== 디버그 =====
1. F5(Step Into) : 현재의 명령문이 호출되는 메소드 속으로 진행하여, 그 첫 문장을 실행하기 전에 멈춘다.
   하지만 자바 라이브러리 클래스 수준까지 들어가므로 단계필터 사용을 체크(Shift+F5)를 하면 필터를 설정한 클래스에 대하서는 Step Over 기능과 같은 기능을 수행한다.
2. F6(Step Over) : 현재의 명령문을 실행하고 다음 명령문 직전에 다시 멈춘다.
3. F7(Step Return) : 현재의 메소드에서 리턴한 직후에 다시 멈춘다.
4. F8(Resume) : 멈추어 있던 쓰레드를 다시 계속 실행한다.
5. Display view(표시) : 창 -> 보기표시 -> 표시 선택하여 소스상에서 필요한 부분을 선택해서 실행시켜 볼 수 있다.  한 순간의 값만 필요할 때 볼 수 있는 반면에 아래놈은 계속적으로 값이 변하는 것을 확인 할 수 있다.
6. Expression view(표현식) : 복잡한 식 혹은 객체를 디버깅 하면서 계속 볼 수있는 창이다.
   마우스 오른버튼 -> 감시 표시식 추가 선택한 후 사용한다.
   환경설정 -> 자바 -> 디버그 -> 세부사항 포멧터 선택 후 보기 편한 식으로 편집하면

   Expression View 에서 결과를  실시간으로 확인 할 수 있다.
7. 디버깅 하면서 소스를 수정하고 프로그램을 다시 시작할 필요 없이 계속 디버깅을 진행 할 수 있다.
   다만 메소드를 추가하거나 필드를 추가하면 프로그램을 다시 시작해야 한다.

8. Drop to Frame(프레임에 놓기) 는 정말 모르겠다.
9. 디버깅 작업을 할때 해당 라이브러리의 소스코드를 첨부하지 않으면 진행상황을 볼 수 없을 경우
   해당 라이브러리에 소스코드를 첨부할 수 있다. 해당 프로젝트 -> 특성 -> Java 빌드경로 -> 라이브러리 -> 소스참조
   편집 버튼을 눌러서 첨부 한다.

 

===== 도움말 =====
"JDT 팁과 요령"이라고 치면 여러가지 흥미로운 팁이 나온다.

 

===== Refactoring =====
1. Pull Down : 수퍼클래스의 멤버나 메소드를 하위 클래스로 내리는 행위
2. Push Up : 하위 클래스의 멤버나 메소드를 상위 클래스로 올리는 행위

 

===== CVS =====
1. CVS 서버로는 윈도우에 CVSNT 최신버젼을 설치하고, [컴퓨터 관리]를 통해서 사용자를 추가한다.
 - CVSNT 를 설치할때 윈도우의 경우 Repositories 를 추가할때 접두어를 사용하지 말고 디렉토리 풀이름(d:/cvs) 이런식
   으로 등록해야 Eclipse 와 에러없이 동기화가 잘 된다.
2. Eclipse 에 CVS 저장소 perspective 에서 새로운 저장소를 등록한 후 HEAD 에서 해당 프로젝트를 체크아웃하면
   자바 perspective 에 등록되는 것을 확인할 수 있다.

 


이것 이외의 단축키 리스트 :  HELP->Help Contents->Java Development User Guide->Reference->JDT Basics

새로운 기능:  HELP->Help Contents->Java Development User Guide->What's new

유용한 기능 :  Tips and tricks


출처 : http://blog.naver.com/wassupnari/100096420344

Flex에서 Datagrid와 Arraycollection에 원하는 항목을 추가하기 위해서는 다음과 같은 명령어를 사용한다.

 

단순히 맨 나중 항목으로 추가할 경우는 다음과 같이 사용한다.

Array1.addItem ({ Data-field : 'Value'});

Grid1.dataProvider.addItem({ Data-field : 'Value});

 

하지만 위치를 지정해서 넣고 싶은 경우 아래와 같이 사용하면 된다.

Array1.addItemAt ({ Data-field : 'Value'}, 위치);

Grid1.dataProvider.addItemAt ({ Data-field : 'Value'}, 위치);

 

예를 들면 다음과 같은 구문이 될 것이다.

ex) GridArray.addItemAt ({ Title : 'Testing', Contents : 'addItem Test ex'}, 1)

위와 같은 경우 GridArray의 1번째 순서에 Title과 Contents라는 항목에 'Testing', 'addItem Test ex'라는 내용이 추가되었다.

 

이미 존재하는 Array에도 새로운 Data-field를 추가할 수 있다.

▣ while문

  
public class Ch6_Ex {
    public static void main (String[] args) {
        int i = 0 ;
        while ( i < 10 ) {
            System.out.println(" i의 값은 " + i) ;
            i ++ ;
        }
    }
}

while문은 루프구조의 상단에 조건식이 존재하므로 조건을 만족하면 내부 로직이 한번도 실행되지 않을 수 있다.


▣ do-while문

  
public class Ch6_Ex {
    public static void main (String[] args) {
        int i = 10 ;
        do {
            System.out.println(" i의 값은 " + i) ;
            i ++ ;
        } while ( i < 10 ) ;
    }
}

do-while문은 루프구조의 하단에 조건식이 존재하므로 조건을 만족하더라도 내부 로직이 한번은 실행된다.


▣ do-while문

  
public class Ch6_Ex {
    public static void main (String[] args) {
        for ( int i = 0; i < 10; i++ ) {
            System.out.println(" i의 값은 " + i) ;
        } 
    }
}

for문은 설정된 조건식과 증감식에 의한 횟수만큼 내부 로직이 실행된다.


▣ break

  
import java.util.* ;

public class Ch6_Ex {
    public static void main (String[] args) {
        int i = 0 ;
        int total = 0 ;
        int counting = 0 ;
        int cost = 0 ;

        Scanner scan  = new Scanner(System.in) ;
        while ( true ) {
            System.out.println(" 금액을 입력하시오 : ") ;
            int cost = scan.nextInt() ;
            if ( cost < 100 )
                break ;

            total += cost ;
            counting++ ;
        }
        System.out.println( "평균금액은 " + total / counting + "원입니다."
    }
}

break문은 해당 루프문을 종료시킨다.


  
        check_loop :
        while ( true ) {
            while (true) {
                if ( cost < 100 )
                    break check_loop ;
            }
        }

중첩 루프문에 레이블을 부여하여 break문을 사용하는 경우 그 레이블에 해당하는 중첩 루프문을 모두 종료시킨다.


▣ continue

  
public class Ch6_Ex {
    public static void main (String[] args) {
        int counting = 0 ;
        for ( int i = 0; i < 10; i++ ) {
            if ( i % 2 = 0 )
                continue ;
            counting++ ;
        } 
        System.out.println("2의 배수의 갯수는 " + counting + "개입니다.") ;
    }
}

if문 안의 조건을 만족할는 경우에만 전체 for문을 루프하며, 만족하지 않는 경우 다시 for문 상단으로 돌아가 로직을 반복한다.

Chapter 06 조건과 반복


▣ if 문


public class Ch6_Ex {
    public static void main (String[] args) {
        if (age >= 20)
            System.out.println("미성년이 아닙니다.");
}
    
public class Ch6_Ex {
    public static void main (String[] args) {
        if (age >= 20)
        {
            System.out.println("미성년이 아닙니다.");
            System.out.println("출입이 가능합니다.");
        }
        else
        {
            System.out.println("미성년자 입니다.");
            System.out.println("출입이 불가능합니다.");
        }
}


▣ 조건 연산자


public class Ch6_Ex {
    public static void main (String[] args) {
       System.out.println(age >= 20 ? "미성년이 아닙니다." : "미성년자 입니다.");
}


▣ 연속적인 if문


public class Ch6_Ex {
    public static void main (String[] args) {
        if (age >= 20)
            System.out.println("성인 입니다.");
        else
            if (age >= 17)
                System.out.println("고등학생입니다.");
            else
                if (age >= 14)
                    System.out.println("중학생입니다.");
                else
                    System.out.println("초등학생입니다.");
}
 
public class Ch6_Ex {
    public static void main (String[] args) {
        if (age >= 20)
            System.out.println("성인 입니다.");
        else if (age >= 17)
            System.out.println("고등학생입니다.");
        else if (age >= 14)
            System.out.println("중학생입니다.");
        else
            System.out.println("초등학생입니다.");
}


▣ switch문

  
public class Ch6_Ex {
    public static void main (String[] args) {
        int number;
        switch (number) {
        case 1 :
            System.out.println("1학년 입니다.");
        case 2 :
            System.out.println("2학년 입니다.");
        case 3 :
            System.out.println("3학년 입니다.");
        case 4 :
            System.out.println("4학년 입니다.");
        default :
            System.out.println("예비대학생 입니다.");
}


Java에서 기본적으로 이해해야 할 내용들


▣ Source File / Class 

 소스파일
 

 클래스 1

 

 메소드 1

 메소드 2

 

 문장 1

 문장 2


 import java.util.Scanner

→ java.util : 패키지

→ Scanner : 클래스


▣ Error

 Compile error

 의미오류 (semantic error) → 서로 다른 타입의 데이터가 포함된 계산

 구문오류 (syntax error) → 문법 규칙에 따르지 않는 문장

 run-time error  예외 처리 (exception)을 사용하여 처리할 수 있음. 
 logical error

 의도치 않는 결과가 발생하는 오류 디버깅 (debugging)을 통해 결함을 고침.


▣ 변수

 기초형  실제 값이 저장 
 정수형 byte, short, int, long 
 실수형 float, double
 논리형 boolean
 문자형 char
 참조형  실제 객체를 가리키는 주소 저장 (클래스, 인터페이스, 배열)


int size;

→ int : 자료형 (type)

→ size : 이름 (name)

→ 식별자 (identifier)의 일종이다.

 식별자는 유니코드 문자와 숫자의 조합으로 만들어진다. 한글도 가능하다.

 첫문자는 일반적으로 유니코드 문자여야하며, 첫문자로 _, $를 사용할 수 있다. (특별한 경우로 제한하는 것을 추천)

 두번째 문자부터는 문자, 숫자, _. $ 등이 가능하다.

 대소문자가 구별된다.

 식별자의 이름으로 키워드 (keyword)를 사용해서는 안된다. 식별자를 보려면 더보기를 눌러보자.

→ 식별자 이름 작성 관례

◆ 클래스명 : 각 단어의 첫글자는 대문자    ex) StaffMenber

변수명, 메소드명 : 첫글자는 소문자, 두번째 단어의 첫글자는 대문자     ex)accNumber

 상수 : 모든 글자를 대문자    ex) MAX_NUMBER


▣ 연산자

ex) 3.14 * radius

→ 피연산자 : 3.14, radius

→ 연산자 : *


 산술 연산자의 종류 및 우선순위


 단항 연산자, 관계 연산자 및 논리 연산자의 종류







1