Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

read text file content line by line using commons-io with delimitter

I was trying to run folowing example from following link

http://www.kodejava.org/examples/53.html
to read and the contents of a text file whose data is separated by delimitters say |


import org.apache.commons.io.FileUtils;  
import java.io.File; import java.io.IOException;
import java.util.List;  
public class ReadFileToListSample {    
      public static void main(String[] args) {    
            //         // Create a file object of sample.txt      
            File file = new File("sample.txt");          
            try {             //             // Here we read a file, sample.txt, using FileUtils          
                  // class of commons-io. Using FileUtils.readLines()    
                  // we can read file content line by line and return          
                  // the result as a List of string.            
                  List<String> contents = FileUtils.readLines(file);              
                  //             // Iterate the result to print each line of the file.          
                  for (String line : contents) {                
                        System.out.println(line);      
                  } catch (IOException e) {          
                        e.printStackTrace();        
                  }    
            }
      }


When I try to run getting compilation error. Do I need to download and add any JAR to run this example. Where I need to place the text file. If I place it under c:\test folder can I modify code as

File file = new File("C:\test\sample.txt");

How do I separate delimtted code in text file as in attachment. My code is not recognizing the org.apache.common, FileUtils, contents etc. please advise.Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
report.txt
ApacheCommons.JPG
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:)