我已将文件中的文本读入数组。我想在另一个类中遍历这个数组(反转一个数组并找到每 5 个元素)。我在另一个类中使用这个数组时遇到问题 - 这个类看不到数组。有人可以帮我吗?
package iterators;
import java.util.*;
import java.io.*;
import iterators.*;
public class Dunno{
int i = 1;
String[] something() throws IOException {
BufferedReader read = new BufferedReader(new FileReader("file.txt"));
StringBuilder sb = new StringBuilder();
String text = read.readLine();
while (text != null) {
sb.append(text);
sb.append("\n");
text = read.readLine();
}
String all = sb.toString();
String film = all;
String znak = ",";
String[] tab;
tab = film.split(znak);
for (i = 0; i < tab.length; i++) {
System.out.println(tab[i]);
}
return tab;
}
}
第二类:
public class Dunno1{
Dunno dunn=new Dunno();
dunn.something();
public String dunn(){
//Iterate
}
}