0

I did try to search for any possible questions regarding this, but none seem to work exactly for me

here is some code I have to read all files in a subdirectory, the method takes the name of the file to look for and its directory

 public static Account FileRead(String fname, String dir) throws blankException {
    File file = new File(dir + fname);
    try {

        Scanner sc = new Scanner(file);

        while (sc.hasNextLine()) {

            String type = sc.nextLine();

            if (type.equals("S") || type.equals("C")) {
                String pin = sc.nextLine();
                double balance = sc.nextDouble();
                String name = sc.next();
                String address = sc.next();
                String date = sc.next();

                if (type.equals("S")) {

                    return new SavingAccount(pin, balance, name, address, date);
                }
                if (type.equals("C")) {

                    return new CheckingAccount(pin, balance, name, address, date);
                }
                throw new blankException("no account type given");
            }
        }
        sc.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}//end file reader

my problem is that for address, the scanner only takes the frist "word", as in if address in the file is "1234 house drive", address is only 1234.how can I have it where address is "1234 house drive"

also, all the files are in this format

type
pin
balance
name
address
date
nafis
  • 5
  • 2

1 Answers1

0

Just take it using .nextLine(). It will take everything that you entered.