MCPcopy Create free account
hub / github.com/GCMiner/GCMiner / ReadCSV

Class ReadCSV

src/main/java/Preprocess/ReadCSV.java:13–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11import java.util.List;
12
13public class ReadCSV {
14
15 //public static List<HashMap> list = new ArrayList<>();
16 public static List<List> listAll = new ArrayList<>();
17
18 public List<List> getListAll() {
19 return listAll;
20 }
21
22 public void setListAll(List<List> listAll) {
23 this.listAll = listAll;
24 }
25
26 public static void main(String[] args) {
27
28 String csvFile = "C:/Users/18710/Desktop/csv/GRAPHDB_PUBLIC_METHODS.csv";
29
30 CSVReader reader = null;
31 try {
32 reader = new CSVReader(new FileReader(csvFile));
33 String[] line;
34 String result = null;
35 int num = 0;
36 while ((line = reader.readNext()) != null&&num<2) {
37 List<HashMap> list = new ArrayList<>();
38 if(num==0){
39 num++;
40 continue;
41 }
42 HashMap<Integer,String> map = new HashMap<>();
43 //System.out.println("Params ="+line[15]);
44 result = line[15];
45
46 //System.out.println("1:"+result);
47 result = result.replaceAll("\"","");
48 //System.out.println("2:"+result);
49 result = result.substring(1,result.length()-1);
50 if(result.isEmpty()){
51 //System.out.println("为空");
52 List<HashMap> l = new LinkedList<>();
53 listAll.add(l);
54 num++;
55 continue;
56 }
57 System.out.println("3:"+result);
58 String str1;
59 if(result.contains("],")){
60 str1 = result.substring(result.indexOf("["),result.indexOf(",",result.indexOf(",")+1));
61 }else{
62 str1 = result.substring(result.indexOf("["),result.indexOf("]")+1);
63 }
64 System.out.println("4:"+str1);
65 int key = Integer.parseInt(str1.substring(1,str1.indexOf(",")));
66 //System.out.println("5:"+key);
67 String value = str1.substring(str1.indexOf(",")+1, str1.lastIndexOf("]"));
68 //System.out.println("6:"+value);
69 map.put(key,value);
70 //System.out.println(JSON.toJSON(map));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected