0
我試圖打印出數組的內容,並且在循環數組以打印元素時遇到問題。它給我的錯誤是:嘗試打印數組參數錯誤
的方法ImportTeams()在類型FILEREAD不適用於參數(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));
}
}
}
啊,我知道這將是小的東西好了。非常感謝!它不會讓我接受另外12分鐘的答案,但我一定會這樣做 – Killian
@基利安:不客氣。祝你好運! – kosa