Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void writeToCSV(List<Map> objectList) {
- String CSV_SEPARATOR = ",";
- try {
- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream("results.csv"), "UTF-8"));
- for (Map objectDetails : objectList) {
- StringBuffer oneLine = new StringBuffer();
- Iterator it = objectDetails.values().iterator();
- while (it.hasNext()) {
- Object value = it.next();
- if(value !=null){
- oneLine.append(value.toString());
- }
- if (it.hasNext()) {
- oneLine.append(CSV_SEPARATOR);
- }
- }
- bw.write(oneLine.toString());
- bw.newLine();
- }
- bw.flush();
- bw.close();
- } catch (UnsupportedEncodingException e) {
- } catch (FileNotFoundException e) {
- } catch (IOException e) {
- }
- }
- Runtime.getRuntime().exec("results.csv");
- Runtime.getRuntime().exec("open results.csv");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement