Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. @Grab(group = 'net.sf.opencsv', module = 'opencsv', version = '2.3')
  2. import au.com.bytecode.opencsv.CSVReader
  3. import au.com.bytecode.opencsv.CSVParser
  4. import au.com.bytecode.opencsv.CSVWriter
  5.  
  6. def TEST_FILE_NAME = 'test.csv'
  7. def TEST_OUTPUT_FILE_NAME = 'testOut.csv'
  8.  
  9. List<String[]> rows = new CSVReader(new FileReader(new File(TEST_FILE_NAME)), CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_ESCAPE_CHARACTER, CSVParser.DEFAULT_QUOTE_CHARACTER, 1).readAll()
  10. // to filter the resultSet:
  11. def rowsOver100 = rows.findAll {it[1].toInteger() > 100}
  12.  
  13. File output = new File(TEST_OUTPUT_FILE_NAME)
  14. if (output.exists()) { output.delete() }
  15.  
  16. // Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
  17. // Returns false if there already existed a file with the same name.
  18. // output.createNewFile() // El withWriter ya crea el archivo si detecta que no existe
  19.  
  20. // TODO: writer en ANSI (para Excel)
  21. output.withWriter { writer ->
  22. new CSVWriter(writer).writeAll(rowsOver100)
  23. }
  24.  
  25. //println rows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement