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 8221153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:48:22+00:00 2026-06-07T13:48:22+00:00

The program is basically about reading from a text file, storing the current data

  • 0

The program is basically about reading from a text file, storing the current data into an ArrayList, then writing data (from user input) into the same text file. Kindly let me know where I am going wrong in this sub-part? The data inside the text file is as follows:

abc t1 1900

xyz t2 1700

The compiler is showing an error at the line output.format("%s%s%s%n",

public class justTesting {
    private Scanner input;
    private Formatter output;
    private ArrayList<Student> tk = new ArrayList<Student>();

    public static void main(String[] args) {
        justTesting app = new justTesting();

        app.create();
        app.writeToFile();
    }

    public void create() {
        Text entry = new Text();
        Scanner input = new Scanner(System.in);

        System.out.printf("%s\n", "Please enter your name, ID, and year: ");

        while (input.hasNext()) {
            try {
                entry.setName(input.next());
                entry.setTelNumber(input.next());
                entry.setDOB(input.next());

                for (int i = 0; i < tk.size(); i++) {
                    output.format("%s%s%s%n", tk.get(i).getName(), tk.get(i)
                            .getTelNumber(), tk.get(i).getDOB());
                }

            } catch (FormatterClosedException fce) {
                System.err.println("Error writing to file.");
                return;
            } catch (NoSuchElementException nsee) {
                System.err.println("Invalid input. Try again: ");
                input.nextLine();
            }
            System.out.printf("%s\n", "Please enter your name, ID, and year: ");
        }
    }

    public void writeToFile() {
        try {
            output = new Formatter("testing.txt");
        } catch (SecurityException se) {
            System.err
                    .println("You do not have write access permission to this file.");
            System.exit(1);
        } catch (FileNotFoundException fnfe) {
            System.err.println("Error opening or creating file.");
            System.exit(1);
        }
    }
}
  • 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-07T13:48:23+00:00Added an answer on June 7, 2026 at 1:48 pm

    I removed %n and it worked. Thanks everyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have a program that filters records from one excel file to another
I have a program where I basically need to load Rich Text from a
I'm writing a Python program for Linux and the program basically uses the terminal
I've got a program made basically from a ListCtrl and has an add button,
Basically I have a script in Python that grabs the text from an open
I have a program that loads a file (anywhere from 10MB to 5GB) a
I am working on a project which basically involves parsing and storing information about
I'm writing a notepad clone to learn more about guis. My program creates a
So what I need is basically to create a java program that runs from
My program basically looks like this: using(XmlReader reader = XmlReader.Create(File.Open(path, FileMode.Open, FileAccess.Reader, FileShare.Read)) {

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.