如何通过返回数组的公共静态中的数组索引调用特定值

时间:2017-06-30 13:28:59

标签: java

public static Iterator<Object[]> readData(String FilePath) throws IOException {
    ArrayList<Object[]> Myarr= new ArrayList<Object[]>();
    String UserDir= System.getProperty("user.dir");
    CSVReader CSVfileread= new CSVReader(new FileReader(UserDir+ FilePath), '\t');

    CSVfileread.readNext();
    String[] nextLine = null;

    while ((nextLine = CSVfileread.readNext()) != null){
        Myarr.add(new Object [] {nextLine});
    }
    System.out.println("Data file has been read");
    CSVfileread.close();
    return Myarr.iterator();    
}

这将读取数据文件,但我无法在带有数组索引的脚本中调用它。我如何调用这个公共静态的每个Myarr值。

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法,

public static ArrayList<Object[]> readData(String FilePath) throws IOException {
    ArrayList<Object[]> Myarr= new ArrayList<Object[]>();
    String UserDir= System.getProperty("user.dir");
    CSVReader CSVfileread= new CSVReader(new FileReader(UserDir+ FilePath), '\t');

    CSVfileread.readNext();
    String[] nextLine = null;

    while ((nextLine = CSVfileread.readNext()) != null){
        Myarr.add(new Object [] {nextLine});
    }
    System.out.println("Data file has been read");
    CSVfileread.close();
    return Myarr;    
}

//外面你可以像

一样打电话
ArrayList<Object[]> output = readData("filepath");
output.get(0) //to get the first value