Reading a wordpad file with 3 columns in Java -
I want to read a text file that contains a space separated value. Values are integers, how can I read it? I want to read each line and after going to the next.
The content is in the form of an example:
"12/11/2012" "00.00.01" 0,100
"12/11/2012 "" 00.00.05 "0,140
" 12/11/2012 "" 00.00.0 9 "0,240
" 12/11/2012 "" 00.00.13 "0,247
The first column is the date, the second is second and the third is liters.
How can I do this a Java program?
I think of using the scanner class I created this program:
import java.io.file; Import java.io.phileNotFoundException; Import java.util.Scanner; Public class scanner example {public static zero main (string algos []) throws FileNotFoundException {text of the file = new file ("C: \ Users \ Desktop \ test \ test.txt"); Scanner scanner = new scanner (text); Int Lincoln = 1; While (scnr.hasNextLine ()) {string line = scnr.nextLine (); System.out.println ("Line" + Line Number + ":" + Line); LineNumber ++; }}}
But I do not have the result of which I have any help?
Using the easy Apache Commons libraries in Java, just add the following dependencies to your palm file (if you Using Maven)
& lt; Dependency & gt; & Lt; Group & gt; Org.apache.commons & lt; / Group & gt; & Lt; ArtifactId & gt; Commons-When & lt; / ArtifactId> & Lt; Version & gt; 1.3.2 & lt; / Edition & gt; & Lt; / Dependencies & gt;
Then you can
file file = new file ("yourFile.txt"); & Lt; String & gt; Line = file utility Roline (file);
You will find each row of your file in the list. Then to get the contents of your file:
for(string line: lines) {string [] columns = line.split ("") // Because your columns differ from one Arrow columns will contain your data
date format format = new simpledetermutation ("dd / mm / yyyy"); white space}
// column1 datedate = format. Format (column [0]); // column2 // I can not find my second column, is it just another or can it be more? // column3 double liters = double. PRAD Double (column [2]);
Comments
Post a Comment