Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Solution {
- public class Input {
- private final String name;
- private final Integer age;
- public Input(String name, Integer age) {
- this.name = name;
- this.age = age;
- }
- public String getName() {
- return this.name;
- }
- public Integer getAge() {
- return this.age;
- }
- }
- public void readFile() throws FileNotFoundException {
- File file = new File("/home/vibhav/input.txt");
- Scanner scanner = new Scanner(file);
- List<Input> inputs = new ArrayList<Solution.Input>();
- while(scanner.hasNextLine()) {
- String nextLine = scanner.nextLine();
- String[] splits = nextLine.split(",");
- String name = splits[0];
- Integer age = Integer.parseInt(splits[1]);
- Input input = new Input(name, age);
- inputs.add(input);
- }
- for (Input input: inputs) {
- System.out.println("Name=" + input.getName());
- System.out.println("Age=" + input.getAge());
- }
- scanner.close();
- }
- public static void main(String[] args) throws FileNotFoundException {
- // TODO Auto-generated method stub
- Solution solution = new Solution();
- solution.readFile();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement