这是我读取 txt 文件的代码,但我似乎无法正确安排文件内容的输出。
这是文件内容:
venti lador 13 男款taguig
Pito dingal 26 雄性 pateros
多尼·马丁内斯 24 男 hagonoy
package testprojects;
import java.io.BufferedReader;
import java.io.FileReader;
public class ReadTextFile {
public static void main(String args[]) throws Exception {
BufferedReader bf = new BufferedReader(new FileReader("C://Users/PAO/Desktop/sampletxt.txt"));
String line;
while ((line = bf.readLine()) != null) {
String[] value = line.split(" ");
for (int x = 0; x < value.length; x++) {
if (x >= 5) {
System.out.println();
}
System.out.print(value[x] + " ");
}
}
}
}
输出:
venti lador 13 男 taguig Pito dingal 26 男 pateros dony martinez 24 男 hagonoy
期望的输出:
venti lador 13 男款taguig
Pito dingal 26 雄性 pateros
多尼·马丁内斯 24 男 hagonoy