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值。
答案 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