본문 바로가기

Java

Couldn't connect to host, port: localhost, 25; timeout -1 Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1 JDK : 1.8 이전에 수행했던 메일 발송 테스트를 다시 하고자 하는데 위 에러가 발생했다. cmd에서 telnet localhost 25 로 접속을 시도해보니 220 코드가 회신되는걸 보니 이클립스 문제인 듯 하다. JDK6 부터 가끔.. IPv6를 사용하려고 하는데 이를 IPv4를 사용하라고 지정해 줄 수 있다. 아래 그림 처럼 실행 환경 옵션에 추가해 준다. -Djava.net.preferIPv4Stack=true
Java File copy with append if exits file import org.apache.commons.io.IOUtils; private void copy(File source, File target){ try { in = new FileInputStream(source); out = new FileOutputStream(target, true); IOUtils.copy(in, out); } catch (IOException ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } FileOutputStream의 생성자 중 두번째 인자는 append 여부.
XML에서 한글 읽어들이기. InputSource is = new InputSource(new InputStreamReader(new FileInputStream("test.xml"), "UTF-8")); 이렇게 하지 않으면 Element를 통해 읽어 들일때 end tag를 인식하지 못해 에러난다. 대략적 전체 코드. try { User user = null; InputSource is = new InputSource(new InputStreamReader(new FileInputStream(file), "UTF-8")); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); if(f..
Criteria 사용할때 주의할 점. 난 Collection을 사용할때 항상 Generic 타입으로 객체를 생성하려한다. 이유야 generic을 사용하면 좀 간편해지니 (캐스팅을 할 필요도 없고..) 이유야 어쨋든 하이버 네이트에서도 제네릭을 붙여보았는데 .. Session session = getHibernateTemplate().getSessionFactory().openSession(); Criteria crit = session.createCriteria(Member.class); crit.add(Expression.eq("userId", member.getUserId())); crit.add(Expression.eq("userPw", member.getUserPw())); List list = crit.list(); 난 이게 될 줄..