我必须从text.txt
文件中读取数据,但我有奇怪的错误,我的输出是:[Ljava.lang.String;@5f0a94c5
.
文件内容text.txt
:
test::test.1::test.2
test2::test2.1::test2.2
test3::test3.1::test3.2
编码:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
public class test {
public static void main(String[] args){
ArrayList<String> data = new ArrayList<String>();
try (BufferedReader br = new BufferedReader(new FileReader("test.txt"))) {
String CurrLine;
while((CurrLine = br.readLine()) != null) {
data.add(CurrLine);
}
String[] dataArray = new String[data.size()];
data.toArray(dataArray);
Arrays.toString(dataArray);
System.out.println(dataArray);
} catch(FileNotFoundException ex) {
System.out.println("FNFE");
} catch(IOException ex) {
System.out.println("IOE");
}
}
}