Here is my code for reading a txt file, but I can't seem to properly arrange the output of the file content.
This is the file content:
venti lador 13 male taguig
pito dingal 26 male pateros
dony martinez 24 male 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] + " ");
}
}
}
}
Output:
venti lador 13 male taguig pito dingal 26 male pateros dony martinez 24 male hagonoy
Desired output:
venti lador 13 male taguig
pito dingal 26 male pateros
dony martinez 24 male hagonoy