似乎您想要的单词被空格分开了。在这种情况下,只需逐行阅读文件,然后使用即可获得所需的字词
String.split(" ")。这是我可能想到的:public class FileSplitter { public static void main(String[] args) throws IOException { File file = new File("input_file.txt"); linkedList<String> words = new linkedList<String>(); int i = 0; Files.lines(file.toPath()). forEachOrdered(line -> words. addAll(Arrays.asList(line.split(" ")))); for(String word:words){ if(word.trim().length() > 0){ System.out.print(word.trim() + " "); if(i++ >= 3){ System.out.println(); i = 0; } } } }}对于您的示例,它返回以下内容:
sys_clock_gettime sys_poll sys_poll sys_clock_gettime sys_poll sys_poll sys_poll sys_clock_gettime sys_poll sys_clock_gettime sys_poll sys_poll sys_poll sys_poll sys_poll sys_pollsys_poll sys_poll sys_socketcall



