Powered by Blogger.
  • Home
  • About
  • Contact
facebook instagram pinterest Email

chuckolet's Blog

Musician & Developer


Image result for java

오랜만에 자바에서 간단한 파일 입출력을 해보았는데

절대 경로를 불러오는 방법이 생각보다 직관적이지 않았다.

기억해두기 위해 포스팅 하기로 했다.

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
public static void main(String[] args) {
    String path = 클래스이름.class.getResource("").getPath(); // 현재 클래스의 절대 경로
    try {
        FileReader fr = new FileReader(path + "myXML.xml");      
        BufferedReader br = new BufferedReader(fr);      
        System.out.println("파일 불러오기 성공!");  }
    catch (FileNotFoundException e) {
        System.out.println("파일이 존재하지 않습니다.");      
        e.printStackTrace();
    }
}
public void FileReader(String inputFile) throws IOException {
    BufferedReader br = new BufferedReader(new FileReader(new File(inputFile)));    
    String buffer = "";
    while((buffer = br.readLine()) != null) {
        System.out.println(buffer);    
    }
    br.close();
}
Colored by Color Scripter
cs
Share
Tweet
Pin
Share
No comments
I found some great website to understand that.


with nice code
Association, Composition and Aggregation in Java

with detailed description
Understanding Association, Aggregation, and Composition


- simplest one
Association Vs Aggregation Vs Composition


In short,

1. Association

  1.1. Association is a relation between two separate classes.
  1.2. Composition and Aggregation are the two forms of association.
  1.3. Association can be one-to-one, one-to-many, many-to-one, many-to-many.
                       Association in Java
                            pic1. one-to-many association

2. Aggregation 

  2.1. it represents Has-A relationship
  2.2. Each class can have different life cycles.

                        Aggregation_1
                           pic2. Aggregation

3. Composition

  3.1. it represents Part-of relationship
  3.2. Each class has same life cycles.



cf)

Aggregation vs Composition

  1. Dependency: Aggregation implies a relationship where the child can exist independently of the parent. For example, Bank and Employee, delete the Bank and the Employee still exist. whereas Composition implies a relationship where the child cannot exist independent of the parent. Example: Human and heart, heart don’t exist separate to a Human
  2. Type of Relationship: Aggregation relation is “has-a” and composition is “part-of” relation.
  3. Type of association: Composition is a strong Association whereas Aggregation is a weak Assocation.
Share
Tweet
Pin
Share
No comments
They listen for different events:
MouseListener
mouseClicked(MouseEvent event)   // Called just after the user clicks the listened-to component.
mouseEntered(MouseEvent event)   // Called just after the cursor enters the bounds of the listened-to component.
mouseExited(MouseEvent event)    // Called just after the cursor exits the bounds of the listened-to component.
mousePressed(MouseEvent event)   // Called just after the user presses a mouse button while the cursor is over the listened-to component.
mouseReleased(MouseEvent event)  // Called just after the user releases a mouse button after a mouse press over the listened-to component
MouseMotionListener
mouseDragged(MouseEvent event)   // Called in response to the user moving the mouse while holding a mouse button down. This event is fired by the component that fired the most recent mouse-pressed event, even if the cursor is no longer over that component.
mouseMoved(MouseEvent event)     // Called in response to the user moving the mouse with no
Add the listeners according to what event you're after.






Reference
Share
Tweet
Pin
Share
No comments
Older Posts

About Me

Unknown
View my complete profile

Categories

  • Android (4)
  • AWS (1)
  • Coding Test (3)
  • Computer (5)
  • etc (1)
  • Git (2)
  • JAVA (3)
  • Linux (6)
  • Machine Learning (7)
  • Music (1)
  • PHP (1)
  • Python (8)
  • React Native (1)
  • SQL (1)
  • Web (12)
  • XML (2)
  • 주식 (1)

Popular Posts

  • 아나콘다 파이썬에서 IDLE 실행하기
  • Solution: CUDA 9.0 설치 실패 오류 (CUDA 9.0 installer failed on windows 10)
  • 에어드로이드(Airdroid) 로컬 연결 모드 접속 방법(원격 연결 모드로만 접속 해결)
  • 우분투 16.04 크롬 설치, 블루 스크린 문제
  • 마우스 오른쪽 클릭으로 CMD 열기 (How do I right click command prompt?)

recent posts

Total Pageviews

Follow Me

  • facebook
  • instagram
  • Google+
  • youtube

Created with by ThemeXpose