Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. public static void writeToCSV(List<Map> objectList) {
  2. String CSV_SEPARATOR = ",";
  3. try {
  4. BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
  5. new FileOutputStream("results.csv"), "UTF-8"));
  6. for (Map objectDetails : objectList) {
  7. StringBuffer oneLine = new StringBuffer();
  8. Iterator it = objectDetails.values().iterator();
  9.  
  10. while (it.hasNext()) {
  11. Object value = it.next();
  12.  
  13. if(value !=null){
  14. oneLine.append(value.toString());
  15. }
  16.  
  17. if (it.hasNext()) {
  18. oneLine.append(CSV_SEPARATOR);
  19. }
  20. }
  21. bw.write(oneLine.toString());
  22. bw.newLine();
  23. }
  24. bw.flush();
  25. bw.close();
  26. } catch (UnsupportedEncodingException e) {
  27. } catch (FileNotFoundException e) {
  28. } catch (IOException e) {
  29. }
  30. }
  31.  
  32. Runtime.getRuntime().exec("results.csv");
  33.  
  34. Runtime.getRuntime().exec("open results.csv");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement