所以我试图计算数组中有多少行,但我不知道该怎么做。我写了这段代码,它读取文件并将内容放入数组中。如何计算数组中的行数?
public static void main(String[] args) throws IOException {
File file = new File("array_list.csv");
FileInputStream fin = null;
try {
fin = new FileInputStream(file);
byte fileContent[] = new byte[(int)file.length()];
fin.read(fileContent);
String fileToArray = new String(fileContent);
//print file
System.out.println(fileToArray);
}
finally {
if (null != fin) {
fin.close();
}
}
}
这是文件 array_list.csv 的内容
569, 985, 97, 13,-94,256, 31, 74, 569,
-45, 601, 29, 19,-1952, 88,256,-69, 601,
1952, 1952,-15, 5,-54, 60, 89, 91, 39,
-601,-97, -6,-26, 89,-66,-601, 26, 28,
-51,-91, 39, 88, 99, 985, -7, 39,-29,
92, 1, 92, 92, 27,-11,-601, 22,-58,
13,-92, 28,-40, 27,-73, 0, 22, 33
我尝试使用 fileToArray.length 位 explipse 返回异常
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
length cannot be resolved or is not a field