본문 바로가기

Programming Practice

파일 이동 1) 기본 - 파일의 정보만 변경. renameTo 사용 - 원본파일객체.renameTo(목적지파일객체) 2)사용 예시 ㄱ. 통신 프로그램에서 파일 이동 시 사용 - client 에서 server 로 파일 전송 시, 전송 완료 후 전송 폴더에서 bak 폴더로 옮길 때 - server 에서 client로부터의 파일 수신 시, 파일 체크 후 tmp 폴더에서 수신 폴더로 옮길 때 3) 사용 방법 - 파일경로는 미리 구성해놓고, 파일명은 파라미터로 받아서 '파일경로/파일명'을 만듦 - new StringBuffer.append(), File.separator, StringBuffer.toString()을 이용 - '/' 를 File.separator 로 설정 4) 예시 String folder = "F:/dev.. 더보기
Socket 통신 1. Socket 통신에 필요한 기능과 해당 기능을 수행하는 class와의 매핑순번 기능 class 비고 1 Connect to a remote machine Socket'Send data' 와 'Receive data'는 동시에 진행이 가능함 2 Send data 3 Receive data 4 Close a connection 5 Bind to a port ServerSocket 6 Listen for incoming data 7 Accept connections from remote machines on the bound port 2. server class 구성 - 여러 client가 동시에 server 에 connect 해서 send data, receive data를 할 수 있음. 따라서 lis.. 더보기
Properties 를 Text로 관리 1. config.properties 작성- key=value- value 가 String 이라도, 앞뒤로 ""를 붙이지 않는다. notepad=notepad.exe file=F:/development/bat/jarTestText.txt 2. ConfigUtil.java 작성 package util; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Properties; public class ConfigUtil { private static Properties props = null; static { try { props = new Properties(); InputStream is = null; is = Cla.. 더보기
bat 명령어 1) 변수 사용 ㄱ. 변수값 설정 : SET 변수명 = 변수값 ㄴ. 변수값 호출 : %변수명% ex) SET CLASSPATH=. SET CLASSPATH=%CLASSPATH%;commons-cli.1.2.jar 2) cmd 화면에 명령어, output 표시하기 명령어, output 표시하기 ECHO ON output 표시하기 ECHO OFF 특정 문자열만 표시하기 ECHO String. 변수라면, %변수명% 'ECHO ON' 일지라도, 명령어 앞에 @가 있으면, 해당 명령어는 화면에 표시되지 않는다. (1차 예시)jarTest.jar 내의 jarTest.JarMainTests class 호출하기. java 에서 호출되는 System.out.println() 을 특정 log 파일에 저장하기 @ECHO O.. 더보기
pointer 1. pointer 와 사용 목적- 변수의 메모리 주소- 2가지 목적 1) 불필요한 변수 복사 피하기 (avoid copy) 2) 변수 값 공유하기 (share data) 2. 연산자- 2가지 연산자( &, * )- 변수가 int 라면, 왼쪽 오른쪽 = & variable -> address * 포인트 변수라는 것을 나타냄. * address -> variable #include int main() { int b = 10; int *a = &b; //b variable 에서 address를 꺼내서 point 변수 a 에 매핑시키기 printf("%i\n", *a); //10 *a = 11; //point 변수 a 에 다른 값(11)을 매핑시키기 printf("%i\n", *a); //11 } 더보기
parameter로 객체 정보를 받아서 객체 생성 Class 객체 선언 및 Class 객체로부터 실제 Class 객체 생성 1) class 자체 사용 Class 더보기
FileFilter 1. 목적 파일 목록을 가져올 때, 파일 유형에 제한 걸기 (java 에서는 file 와 directory를 모두 같은 file로 생각한다.) ex. 특정 directory 내에서 directory 가 아닌 file 만 가져오기 / 특정 directory 내에서 file 이 아닌 directory 만 가져오기 2. 사용 예 File dir = new File("F:/books"); File[] files = dir.listFiles( new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isFile(); //file 만 가져오기 //return pathname.isDirectory(); //directory .. 더보기
multi thread 1. multi thread 란?1) 하나의 processor 가 여러개의 task를 함께 수행하는 것. 엄밀히 말해 동시에 수행하는 것은 아니다.2) 여러개의 task에 대해 개별로 thread를 만들고, start를 시켜 수행한다.3) thread가 생길 때마다 call stack이 따로 생기며, process 는 JVM 의 thread scheduler 의 결정에 따라 stack 들 사이를 옮겨다니며(move back and forth between stacks), task들을 함께 수행한다. (thread 실행 상태를 사용자가 설정할 수 없음) 2. thread 사용 방법1) thread 실행 code를 담을 class 작성- Runnable 이라는 interface 를 implement 해야 한.. 더보기
NIO vs. BIO NIO BIO 약어 Non Blocking IO Blocking IO 개괄 X client에 의해 호출된 작업은 작업이 완료될 때까지 client의 다른 작업을 막는다.(called operation will block the caller until the operation is completed) Server X 1 connection - 1 threadNIO 보다 빠르다. 그러나 수백만이 동시에 접속했을 때 수백만의 connection마다 하나씩의 thread를 부여할 수는 없다. Client command -> informed request -> wait Apache MINA 는 NIO 방식을 지원한다. 더보기
query XML 에서 사용하는 Vo(Entity) type 의 alias 지정 1. 배경query XML 에서 parameterType 이나 resultMap 에서 Vo(Entity) 의 type(경로.class명)이 필요할 때가 있다. (parameter 나 result 가 Vo(Entity)에 담겨져 있을 때)이때 type(경로.class명)을 type 이 필요할 때마다 적어주는 것은 불필요한 반복이다. 따라서 type 에 alias를 주고, alias를 type 에 적어주면, 불필요한 반복을 피할 수 있다. 2. 사용1) mybatis-config.xml 2) DispatcherServlet-context.xml 3) queryXml 에서 type 에 경로.class명 대신 alias를 사용 더보기