我试图打印出数组的内容,并且在循环遍历数组以打印元素时遇到了问题。它给我的错误是:
FileRead 类型中的 ImportTeams() 方法不适用于参数 (int)
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class FileRead {
public String[] ImportTeams(){
String[] Teams;
BufferedReader br = null;
int linecount = 0;
try {
br = new BufferedReader(new FileReader("filepath"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
while (br.readLine() != null){
linecount ++;
}
br.close();
br = new BufferedReader(new FileReader("filepath"));
if (linecount % 2 != 0) {
linecount ++;
}
Teams = new String[linecount];
String teamcounter;
int arraycount = 0;
while ((teamcounter = br.readLine()) != null) {
Teams[arraycount] = teamcounter;
arraycount++;
}
return Teams;
} catch (IOException e1) {
e1.printStackTrace();
}
return null;
}
public static void main(String args[]){
FileRead fr = new FileRead();
for(int i =0; i <fr.ImportTeams().length; i++){
System.out.println(fr.ImportTeams(i));
}
}
}