0

I am currently having problems to show the latest information stored in the file after saving it. If I save the file and try to read from it, it'll read from the start of the file. How would i modify my code for it to read the latest entry made by the application and display it?

Address class

public void SaveToFile (FileWriter awriter){

        try{ 
            awriter.write(name + System.getProperty("line.separator"));
            awriter.write(house_name + System.getProperty("line.separator"));
            awriter.write(String.valueOf(house_no) + System.getProperty("line.separator"));
            awriter.write(street + System.getProperty("line.separator"));
            awriter.write(area + System.getProperty("line.separator"));
            awriter.write(post_code + System.getProperty("line.separator"));
            awriter.write(town + System.getProperty("line.separator"));
            awriter.write(country + System.getProperty("line.separator"));

            writer.flush();
            writer.close();
            writer = null;

        } catch (IOException ioe){
            System.out.println("Failed to save");
        }

    }
public void LoadFromFile(BufferedReader areader){

        try{
            name = areader.readLine();
            house_name = areader.readLine();
            house_no = Integer.valueOf(areader.readLine());
            street = areader.readLine();
            area = areader.readLine();
            post_code = areader.readLine();
            town = areader.readLine();
            country = areader.readLine();


        }
        catch(IOException ioe){
        }

    }

Branch class

    public void SaveToFile(boolean append){

        branchAddressFile = "branchAddress.txt";

        try{

           FileWriter awriter = new FileWriter(new File(branchAddressFile),append);

            theAddress.SaveToFile(awriter);           
            awriter.write(BankName + System.getProperty("line.separator"));
            awriter.write(WorkingHours + System.getProperty("line.separator"));
            awriter.write(Manager + System.getProperty("line.separator"));
            awriter.write(SortCode + System.getProperty("line.separator"));

            awriter.flush();
            awriter.close();
        } catch (IOException ioe){
            System.out.println("Error while saving Head Office Address");
        }
    }

    public void LoadFromFile(String filename){

        filename = "branchAddress.txt";

        String record;
        FileReader reader;

        try{
            reader = new FileReader(filename);
            BufferedReader bin = new BufferedReader(reader);

            theAddress.LoadFromFile(bin);        
            BankName = bin.readLine();
            WorkingHours = bin.readLine();           
            Manager = bin.readLine();
            SortCode = bin.readLine();

            bin.close();
            bin = null;
        }
        catch(IOException ioe){

        }
    }

So if I have this info saved in the text file,

d
e
11
f
g
h
i
j
a
b
c
00-00-00
4
5
6
7
8
9
10
11
1
2
3
00-00-00

It will only display which was the first entry.

d
e
11
f
g
h
i
j
a
b
c
00-00-00

What I want is

4
5
6
7
8
9
10
11
1
2
3
00-00-00
Azeem Shah
  • 13
  • 4
  • 2
    That https://stackoverflow.com/questions/9671126/how-to-read-a-file-from-a-certain-offset-in-java can solve this problem? – mrossini Nov 28 '19 at 19:22
  • the problem is that if i keep adding new items in the file, how would i read the latest edition? – Azeem Shah Nov 29 '19 at 21:31

0 Answers0