开发者

For some reason String array values are being concatenated into a single value when I don't want this

开发者 https://www.devze.com 2023-03-27 13:19 出处:网络
This is driving me insane. I have a String[] (array) which I get using the OpenCSV library. It seems to work fine when I iterate through it from a method in the same class, but when I try to get the

This is driving me insane.

I have a String[] (array) which I get using the OpenCSV library. It seems to work fine when I iterate through it from a method in the same class, but when I try to get the String[] from another class I get an array with a single element, which looks like all the elements of the String[] concatenated together.

I then put the array values into a list (as below) and I still get the same kind of thing happening.

From the same class I get this output (which is desired) :

 ---- 
OpCode
 ---- 
Date
 ---- 
Depth (m)
 ---- 
Waypoint
 ---- 
Latitude
 ---- 
Longitude
 ---- 
Left Cam

开发者_C百科Using this code

public static void main(String[] args){
    CSVScrawler scrawl = new CSVScrawler("/avalidfile.txt");
    scrawl.readColNames();
}


public List<String> readColNames() {

    List<String> colNames = new ArrayList<String>();
    try {
    data = reader.readAll(); } catch (FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); }
    String[] header = data.get(calcHeaderLineNo());
    for(int i=0;i<header.length;i++){
        colNames.add(header[i]);
    System.out.println(" ---- ");
    System.out.println(colNames.get(i));

    }
    return colNames;
}

When I call the same thing from another class I get this (which is not what I want):

  ---- 
OpCode  Date    Depth (m)   Waypoint    Latitude    Longitude   Left      Cam   

The relevant code looks like this:

CSVScrawler csv = new CSVScrawler(uploadedFile.getReader());
// uploadedFile is a FileBean object (from the Stripes framework)
colNames = csv.readColNames();

The constructors are:

public CSVScrawler(String location) {
    this.location = location;
    try {
        reader = new CSVReader(new FileReader(location), '\t'); } catch (FileNotFoundException e) { e.printStackTrace();
    }
}

public CSVScrawler(Reader r){
    reader = new CSVReader(r);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消