62,614
社区成员
发帖
与我相关
我的任务
分享
String[] array = Files.lines(Paths.get("D:/1.txt")).toArray(String[]::new);
public static void main(String[] args) throws IOException {
String[] names = (String[])Files.lines(Paths.get("path to file"))
.collect(Collectors.toList()).toArray();
}
public class Test3 {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new FileReader(
"C:\\Users\\Administrator\\Desktop\\1.txt"));
String line = null;
List<String> list = new ArrayList<String>();
while ((line = in.readLine()) != null) {
String temp = line.trim();
if (temp != null && !"".equals(temp))
list.add(temp);
}
String[] arr = (String[]) list.toArray(new String[list.size()]);
for (String s : arr)
System.out.println("===" + s);
}
}