import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.LinkedHashMap;

import java.util.List;

import java.util.Map;



public class TestCSV {


public static void main(String[] args) throws IOException {

List<Map> list = new ArrayList<Map>();

Map<String, String> mapTitle = new LinkedHashMap<String, String>();

mapTitle.put("num", "순번");

mapTitle.put("num1", "제목");

mapTitle.put("num2", "내용");

mapTitle.put("num3", "기타1");

mapTitle.put("num4", "기타2");

mapTitle.put("num5", "기타3");

mapTitle.put("num6", "기타4");

mapTitle.put("num7", "기타5");

mapTitle.put("num8", "기타6");

mapTitle.put("num9", "기타7");

list.add(mapTitle);

for(int i=0; i<10000; i++){

Map mapContents = new LinkedHashMap();

mapContents.put("key1", "value1 : " + i);

mapContents.put("key2", "value2 : " + i);

mapContents.put("key3", "value3 : " + i);

mapContents.put("key4", "value4 : " + i);

mapContents.put("key5", "value5 : " + i);

mapContents.put("key6", "value6 : " + i);

mapContents.put("key7", "value7 : " + i);

mapContents.put("key8", "value8 : " + i);

mapContents.put("key9", "value9 : " + i);

mapContents.put("key10", "value10 : " + i);

list.add(mapContents);

}

BufferedWriter out = new BufferedWriter(new FileWriter("C:\\Users\\e1x00.HIMARTINFRA\\Desktop\\out.csv"));

String str = "";

Iterator<String> iterator = list.get(0).keySet().iterator();

   while (iterator.hasNext()) {

       String key = (String) iterator.next();

       str += list.get(0).get(key) + ",";

   }

   

   str = str.substring(0, str.length()-1);

   out.write(str);

   out.newLine();

for(int i=1; i<list.size(); i++){

str = "";

Iterator<String> iter = list.get(i).keySet().iterator();

   while (iter.hasNext()) {

       String key = (String) iter.next();

       str += list.get(i).get(key) + ",";

   }

   str = str.substring(0, str.length()-1);

   out.write(str);

   out.newLine();

}


out.close();

}

}






+ Recent posts