본문 바로가기

Java

[java] BufferedReader.. String word_list_dir = "d:/java/text.txt"; File dataDir = new File(word_list_dir); if(dataDir.isHidden() || !dataDir.exists() || !dataDir.canRead()) { return; } try { BufferedReader in = new BufferedReader( new FileReader ( dataDir )); while( (buffer = in.readLine()) != null ) { //row 단위 문장을 처리합니다. } }catch(Exception e){ } ................................ import java.io.*; public class TextFileC.. 더보기
[java] TreeSet과 Comparable TreeSet을 생성 할 때 Comparator를 지정해주지 않으면 저장하는 객체에 구현된 정렬방식에 따라 정렬하여 저장한다. TreeSet set1 = new TreeSet(); TreeSet set2 = new TreeSet(new Descending()); //TreeSet(Comparator c) int[] score = {30,50,10,20,40}; for(int i = 0; i < score.length; i++) { set1.add(new Integer(score[i])); set2.add(new Integer(score[i])); } class Descending implements Comparator { public int compare(Object o1, Object o2) { if(.. 더보기
[JAVA] DecimalFormat import java.text.DecimalFormat; import java.util.GregorianCalendar; public class TestDecimal { public static void main(String[] args) throws Exception { DecimalFormat money = new DecimalFormat("#,#00"); double amount = 444444444.444444444; System.out.println("txtValidFlag : " + money.format(amount)); } } -> 444,444,444 DecimalFormat money = new DecimalFormat("#,#00"); 를 DecimalFormat money = new.. 더보기
[JAVA] classloader#getSystemResourceAsStream() public static Properties getProperties(String filePath) throws IOException{ //ClassLoader로 InputStream 생성 //InputStream is = ClassLoader.getSystemResourceAsStream(filePath); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath); Properties props = new Properties(); props.load(is); return props; } getClass().getResourceAsStream(filePath) 와 같음. 단 getClass()... 더보기
[JAVA] GregorianCalendar // 2008년 3월 10일 0시 0분 0초 GregorianCalendar start = new GregorianCalendar(2008,2,10); //2008년 3월 16일 23시 59분 59초 GregorianCalendar end = new GregorianCalendar(2008,2,16,23,59,59); //현재시간 GregorianCalendar currentCal = new GregorianCalendar(); //2008년 3월 10일 0시 0분 1초 ~ 3월 16일 23시 59분 58초까지.. boolean between = currentCal.after(start) && currentCal.before(end); after, before는 해당 시간을 포함하지 않는다. parame.. 더보기