java - Extra Carriage Returns while reading CSV -


I have some CSV files that I am trying to use Java. For the first time I send a line from the CSV file and send it to another method for processing with the following code: ( file: filesToBeRead) {file csvFile = new file (for file

  TempFile); Scanner scanner = new scanner (csvFile); Scanner.useDelimiter ("[\ n \ r]"); Scanner.next (); While (scanner.hasNext ()) {string temp = scanner.next (); Println (temporary); // datastorage.enterRow (temp); }}   

The output of the above code is:

  A AI277 | DEL | MUB | 05-12-2013 | 0600 | 4.10 | 5500 | Y | EB AI279 | MAB | 10-12-2013 | 0630 | 4.30 | 4900 | Y E AI289 | MAB | 10-12-2013 | 0830 | 4.00 | 5650 | Y EB AI278 | DEL | MUB | 17-12-2013 | 1830 | 4.20 | 5300 Y E AI278 | DL | Mub | 20-12-2013 | 1430 | 3.45 | 6500 | En | EB   

Where should the output be:

  A AI277 | DEL | MUB | 05-12-2013 | 0600 | 4.10 | 5500 | Y EB AI279 | DEL | MUB | 10-12-2013 | 0630 | 4.30 | 4900 | Y E AI28 9 | DL | Mub | 10-12-2013 | 0830 | 4.00 | 5650 | Y EB AI278 | DL | Mub | 17-12-2013 | 1830 | 4.20 | 5300 Y E AI278 | DEL | MUB | 20-12-2013 | 1430 | 3.45 | 6500 | En | EB   

What is actually happening and where is this additional carriage return (\ r) coming from Regex is set up appropriately?

"post-text" itemprop = "text">

The following regex will match one or more new lines or a carous return;

  "[\ N \ r] + "  

Just set the overhead regs as a delimiter; it changes the scanner.useDelimiter (" [\ n \ r \ "]); From the line

  scanner.useDelimiter ("[\ n \ r] +");    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -