Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a non-static class named ConactsFile that opens a text file5-10 contacts

ID: 3616675 • Letter: C

Question

create a non-static class named ConactsFile that opens a text file5-10 contacts names when the file name is passed to theconstructor, and loads the names into a ArrayList<String>.create individual methodss for opening the file, reading the namesinto the collection object, and one that returns the collection public static void main(String[ ] argcs) { ContactsFIle myFile = newContactsFIle("MyContacts.txt") ArrayList<String> myList = myFIle.getList(); -------------- } you will have to create your own text file of 5-10 names. thename are stored in the text file as follows: le Henrry Lady Gala -----

public static void main(String[ ] argcs) { ContactsFIle myFile = newContactsFIle("MyContacts.txt") ArrayList<String> myList = myFIle.getList(); -------------- } you will have to create your own text file of 5-10 names. thename are stored in the text file as follows: le Henrry Lady Gala -----

{ ContactsFIle myFile = newContactsFIle("MyContacts.txt") ArrayList<String> myList = myFIle.getList(); -------------- } you will have to create your own text file of 5-10 names. thename are stored in the text file as follows: le Henrry Lady Gala -----

Explanation / Answer

public class mycram
{
    public static void main(String args[])
{
               
try{
   FileReader fr=new FileReader("contacts.txt");
   BufferedReader br=new BufferedReader(fr);
  
  ArrayList al=new ArrayList();
    
   String line=br.readLine();
   while(line!=null)
   {
   System.out.println(line);
   al.add(line);
   line=br.readLine();
   }

br.close();
fr.close();
}catch(IOException ioex)
{
System.out.println(ioex);
}
}
}