Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Grab(group = 'net.sf.opencsv', module = 'opencsv', version = '2.3')
- import au.com.bytecode.opencsv.CSVReader
- import au.com.bytecode.opencsv.CSVParser
- import au.com.bytecode.opencsv.CSVWriter
- def TEST_FILE_NAME = 'test.csv'
- def TEST_OUTPUT_FILE_NAME = 'testOut.csv'
- 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()
- // to filter the resultSet:
- def rowsOver100 = rows.findAll {it[1].toInteger() > 100}
- File output = new File(TEST_OUTPUT_FILE_NAME)
- if (output.exists()) { output.delete() }
- // Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
- // Returns false if there already existed a file with the same name.
- // output.createNewFile() // El withWriter ya crea el archivo si detecta que no existe
- // TODO: writer en ANSI (para Excel)
- output.withWriter { writer ->
- new CSVWriter(writer).writeAll(rowsOver100)
- }
- //println rows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement