Jawn78

Untitled

Jun 20th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package jrex;
  7.  
  8. import java.io.FileNotFoundException;
  9. import java.io.IOException;
  10. import java.io.Reader;
  11. import java.nio.file.Files;
  12. import java.nio.file.Paths;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. import org.apache.commons.csv.CSVFormat;
  16. import org.apache.commons.csv.CSVParser;
  17. import org.apache.commons.csv.CSVRecord;
  18.  
  19. /**
  20.  *
  21.  * @author jonat
  22.  */
  23. public class company_link_csv_reader {
  24.    private static final String SAMPLE_CSV_FILE = "./sample.csv";
  25.    
  26.    public static List<String> main() throws IOException ,FileNotFoundException{
  27.         try (
  28.             Reader reader = Files.newBufferedReader(Paths.get(SAMPLE_CSV_FILE));
  29.             CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT);
  30.         ) {
  31.             List<CSVRecord> csvRecords = csvParser.getRecords();
  32.             List<String> company_ink_list = new ArrayList<String>();
  33.  
  34.         int x = 0;
  35.       while(x < csvRecords.size()){
  36.            //Get the company page
  37.            CSVRecord recordlist = csvRecords.get(x);
  38.            String[] print = recordlist.toString().split(",");
  39.            //int ll = print[3].length();
  40.            String linkstrings = print[3].replace("values=[", "").replace("]", "").replace(" ","").replace("https://", "").replace("http://", "");
  41.            company_ink_list.add(linkstrings);
  42.            x++;
  43.             }
  44.            
  45.    //System.out.println(csvRecords);
  46.    return company_ink_list;
  47.         }  }
  48.    
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment