Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.File;
- class ReadFile {
- public static void main(String args[ ]) {
- Engine f = new Engine();
- f.openFile();
- f.printFile();
- f.closeFile();
- }
- }
- class Engine {
- private Scanner f;
- private String name, surname, age;
- void openFile() {
- try {
- f = new Scanner(new File("U1.txt"));
- } catch(Exception e) {
- System.out.println("File doesn't exists");
- }
- }
- void printFile() {
- while(f.hasNext()) {
- name = f.next();
- surname = f.next();
- age = f.next();
- System.out.printf("%s %s %s\n", name, surname, age);
- }
- }
- void closeFile() {
- f.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment