Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:14:21+00:00 2026-06-04T05:14:21+00:00

Here is my code: public boolean readFromFileBooking() { boolean isFileBooking = true; try {

  • 0

Here is my code:

public boolean readFromFileBooking()
    {
       boolean isFileBooking = true;
        try 
        {
            BufferedReader reader = new BufferedReader(new FileReader("bookings.txt"));   
            String data = reader.readLine();   
            if (data == null)   
            {
                System.out.println("No Bookings Have Been Made . . . .");
            }    
 data = reader.readLine();  
 reader.close();            
}

Here is the sequence:

  1. Write array into a text file
  2. Stop/exit from the system
  3. On restart load the previous array in the text file so it can be used again.

The problem is whenever I start a new system, the text file will be overwritten by a new array. Actually I want the new array become a new list in ArrayList.

Can you guys share to me how to load the previous data in a new system? How to load/copy the previous data in text file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:14:23+00:00Added an answer on June 4, 2026 at 5:14 am

    This will write out an array of integers into a file with each number separated by a space. It will then read them back in and store them as an arraylist. I have ignored the exception handling to focus on the IO.

    public static void main(String[] args) {
        int[] array = { 1, 2, 3 };
        writeOut(array);
        List<Integer> list = readIn();
        for (Integer num : list) {
            System.out.print(num + " " );
        }
    }
    
    public static List<Integer> readIn() {
        final File file = new File("file.txt");
        List<Integer> list = new ArrayList<Integer>();
        Scanner scan;
        try {
            scan = new Scanner(file);
            while (scan.hasNextInt()) {
                list.add(scan.nextInt());
            }
        } catch (FileNotFoundException e) {
        }
        return list;
    }
    
    public static void writeOut(int[] array) {
        final File file = new File("file.txt");
    
        try {
            file.createNewFile();
            final FileWriter writer = new FileWriter(file);
    
            for (int i = 0; i < array.length; i++) {
                writer.write(Integer.toString(array[i]) + " ");
            }
            writer.close();
            writer.flush();
        } catch (final IOException e) {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the code (java): class prime { public static boolean prime (int a,
In the following code: public class A { public A():this(null){} public A(string b){/*code here*/}
Here is my code : public static void main(String[] args) { // System.setProperty( //
Here is the code: public IEnumerable<UserSummary> getUserSummaryList() { var db = new entityContext(); List<UserSummary>
Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
here is my code now: public boolean onTouchEvent(MotionEvent event) { int action = event.getAction();
Here is My Code: public boolean onTouchEvent(MotionEvent cv){ int x=(int)cv.getX(); int y=(int)cv.getY(); // here
I'm getting a NullPointerException on my Dialog. Here's my code: @Override public boolean onDoubleTap(MotionEvent
Here is my code: public class Test { static { main(null); } public static
So here is my code: public MyClass (int y) { super(y,x,x); //some code }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.