我正在尝试从此方法返回一个数组列表
import java.io.*;
import java.util.*;
/** The class reader read the file 2RainfallDataLanc.txt and stores is as an ArrayList.
* It also parses the variables within the file by white spaces, making variables accessible.
*
*/
public class reader {
public ArrayList<String[]> getRows(){
try {
BufferedReader reader = new BufferedReader(new FileReader("2RainfallDataLanc.txt"));
String line = null;
ArrayList<String[]> rows = new ArrayList<String[]>();
while((line=reader.readLine())!=null)
{String[] row = line.split("\\s+");
rows.add(row);
}
for (String[] row : rows) {
System.out.println(Arrays.toString(row));
return rows;
}
} catch (IOException e) {
}
return null;
}
}
因为我希望在另一个课程中使用它。第二类目前看起来像这样:
public class mean extends reader{
public static void main(String[] args) {
reader newarray = new reader();
}
}
有人可以告诉我我做错了什么吗?每当我尝试返回行时,我都会收到一条错误消息,指出 void 方法无法返回值。