String[] quarters = new String[100] ;
quarters[] = information(fileCheck) ;
public static string information(String a)
{
Scanner inFile = new Scanner (new File(a)) ; // opens connection with file
while (inFile.hasNext()) // loops while more lines in file
{
String line = inFile.nextLine() ; // brings in next line to be broken up
String[] tokens = line.split(", ") ; //stores lines into array tokens
}
inFile.close() ; // close connection to file
return tokens[] ;
} // end information
最佳答案
这不是 Java:
return tokens[] ;
也许您的意思是返回 token 数组:
return tokens;
如果是这样,请声明该方法返回 String[]
而不是 String
。
此外,您没有向我们显示这些线路的位置:
String[] quarters = new String[100] ;
quarters[] = information(fileCheck) ;
据我们所知,它们赤裸裸地出现在类中,而不是出现在任何方法或构造函数中。如果是这样,那就不是 Kosher Java,因为第二行不是声明,需要位于方法或构造函数中。
关于java - 转到方法,从文件中提取信息,然后在分割后返回它。我收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15421680/