Task: Display a list of all smartphones grouped by manufacturer. Question: How to read the file so that all unique columns (Serial Number, Manufacturer, Model, Operating System, RAM Size) are read separately and recorded with the ArrayList into an array and then each line can be passed through the form of getters. Here is the form:
public class IntoBox { static void p(String s) { System.out.println(s); } public int number; public String maker; public String model; public String os; public int ram; public IntoBox (int number, String maker, String model, String os, int ram){ this.number = number; this.maker = maker; this.model = model; this.os = os; this.ram = ram; this.i = i; } //getters public int getNumber(){ return number; } public String getMaker(){ return maker; } public String getModel(){ return model; } public String getOs(){ return os; } public int getRam(){ return ram; } //setters public void setNumber(int number){ this.number=number; } public void setMaker(String maker){ this.maker=maker; } public void setModel(String model){ this.model=model; } public void setOs(String os){ this.os=os; } public void setRam(int ram){ this.ram=ram; }
Sample data from file: 1111 Samsung A5 Android 1000
As I read the file:
ArrayList<String> arrayList = new ArrayList<String>(); File inputFile = new File("C:\\data\\data.txt"); BufferedReader reader = new BufferedReader(new FileReader(inputFile)); while (reader.ready()) arrayList.add(reader.readLine()); reader.close();