package mug13; /* * FileCopier copies the usernames and passwords * from the login file and stores them in an array * * * @author Brett McMillian * @author Louisa Poythress */ import java.io.*; public class LoginFileCopier { public Object[] copyFile(String file) throws FileNotFoundException, IOException { FileReader textFR = new FileReader(file); BufferedReader textFLR = new BufferedReader(textFR); Object[] arrayOfNamesAndPasswords = new Object[20]; int i = 0; while (true) { textFLR.skip(6); String username = (String) textFLR.readLine(); textFLR.skip(10); String password = (String) textFLR.readLine(); if (username == null) break; if (i == arrayOfNamesAndPasswords.length) { Object[] newCopy = new Object[2*arrayOfNamesAndPasswords.length]; for (int n = 0; n < arrayOfNamesAndPasswords.length; n++) { newCopy[n] = arrayOfNamesAndPasswords[n]; } arrayOfNamesAndPasswords = newCopy; } System.out.println(username); System.out.println(password); arrayOfNamesAndPasswords[i] = username; arrayOfNamesAndPasswords[i+1] = password; i += 2; } return arrayOfNamesAndPasswords; } }