txt文件长这样,如何获取里面数据,再将数据已一行一行方式存入数组中
void txtRead() throws UnsupportedEncodingException {
Path path = Paths.get("/home/bugpz/a.txt");
byte[] data = new byte[0];
try {
data = Files.readAllBytes(path);
} catch (IOException e) {
e.printStackTrace();
}
String result = new String(data, "utf-8");
ArrayList<Object> objects = new ArrayList<>();
for (String retval: result.split("\n")){
objects.add(retval);
}
System.out.println(objects);
}