posted by 셀로브 2013. 12. 18. 19:12

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.io.*;

public class ReadWriteTextFile {

    static public String getContents(File aFile) {
        //...checks on aFile are elided
        StringBuilder contents = new StringBuilder();

        try {
            //use buffering, reading one line at a time
            //FileReader always assumes default encoding is OK!
            BufferedReader input =  new BufferedReader(new FileReader(aFile));
            try {
                String line = null; //not declared within while loop
                /*
                 * readLine is a bit quirky :
                 * it returns the content of a line MINUS the newline.
                 * it returns null only for the END of the stream.
                 * it returns an empty String if two newlines appear in a row.
                 */

                while (( line = input.readLine()) != null){
                    contents.append(line);
                    contents.append(System.getProperty("line.separator"));
                }
            }
            finally {
                input.close();
            }
        }
        catch (IOException ex){
            ex.printStackTrace();
        }


        return contents.toString();
    }

    static public void setContents(File aFile, String aContents)
            throws FileNotFoundException, IOException {
        if (aFile == null) {
            throw new IllegalArgumentException("File should not be null.");
        }
        if (!aFile.exists()) {
            throw new FileNotFoundException ("File does not exist: " + aFile);
        }
        if (!aFile.isFile()) {
            throw new IllegalArgumentException("Should not be a directory: " + aFile);
        }
        if (!aFile.canWrite()) {
            throw new IllegalArgumentException("File cannot be written: " + aFile);
        }

        //use buffering
        Writer output = new BufferedWriter(new FileWriter(aFile));
        try {
            //FileWriter always assumes default encoding is OK!
            output.write( aContents );
        }
        finally {
            output.close();
        }
    }

    public static void main (String... aArguments) throws IOException {
        File testFile = new File("C:\\PageCount.txt");
        System.out.println("Original file contents: " + getContents(testFile));
        setContents(testFile, "The content of this file has been overwritten...");
        System.out.println("New file contents: " + getContents(testFile));
    }
}


'언어(Language) > JAVA' 카테고리의 다른 글

No enclosing instance of type 컴파일 오류  (0) 2013.12.19
Java 한글 <-> 유니코드 변환  (0) 2013.12.19
IS-A 관계와 HAS-A 관계  (0) 2013.10.20
캡슐화  (0) 2013.10.20
다형성  (0) 2013.10.20

DB

posted by 셀로브 2013. 12. 16. 20:32

http://blog.naver.com/blueday9404?Redirect=Log&logNo=110174448144

http://blog.naver.com/doryjj?Redirect=Log&logNo=193946953

http://blog.naver.com/zsgth?Redirect=Log&logNo=140196852031

1. mysql 안에 테이블과 투플을 생성한 다음

2. jdbc 드라이버를 설치하고

3. 자바를 통해 데이터베이스와의 연결을 확인해보는 작업을 할 것이다!!

 

 

- 먼저, 기본적인 테이블을 생성하고 투플 하나를 추가하였다.

 

< jdbc 드라이버 설치 >

- 다음 사이트에서 mysql 의 JDBC 드라이버인 Connector/J를 다운받는다.

www.mysql.com/products/connector/

 

 

- 다운받은 파일을 설치하고 나면,  MySQL 경로안에 bin 파일이 생성되는데, 이 파일을 jdk와 jre 안에 복사하여야 한다.

- 구체적인 경로로 설명하면  " C - Program Files - MySQL - MySQL Connector J " 안의 mysql-connector-java-5.1.26-bin  파일을,

 C - Program Files - jdk 1.6.0_37 - jre - lib - ext

 C - Program Files - jre7 - lib - ext

 경로안에 복사해야 한다. (jdk안의 jre말고, jre가 설치되어 있지 않다면 복사하지 않아도 되는듯 하다 ) 





 

 

< 자바-데이터베이스 프로그래밍 >

- DB연결을 테스트하는 소스를 작성하였다.

import java.sql.*;

public class DB {
 public static void main(String[] args) {
  Connection conn = null;
  try {
   Class.forName("com.mysql.jdbc.Driver");
   conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/son","s-----","-----");

                                      :// 호스트명 : 포트번호 / 데이터베이스이름" , "아이디" , "패스워드"); 를 의미한다.
    System.out.println(" db에 접속했습니다. ");
   conn.close();
  }
  catch ( ClassNotFoundException cnfe){
   System.out.println("해당 클래스를 찾을수 없습니다. " + cnfe.getMessage());
  }
  catch( SQLException se){
   System.out.println(se.getMessage());
  }

 }

} 

- 그리고 실행결과를 통해 연결됐음을 확인하였다!

( jdbc의 설치환경이 올바르지 않을 경우 "해당클래스를 찾을수 없습니다" 오류가 뜬다고 한다 )

 

posted by 셀로브 2013. 12. 10. 17:38

레이블링(Labeling)은 인접한 화소끼리 같은 번호를 붙이는 행위를 의미합니다.




전체 픽셀을 검사하여 특정 픽셀을 찾습니다. 목표 픽셀을 찾은 경우 인접한 픽셀에 동일한 조건의 픽셀이 존재하는지 검사하고 같은 번호로 묶어줍니다.