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

  • Home
  • SEARCH
  • 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 8703395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:51:31+00:00 2026-06-13T02:51:31+00:00

I am writing a program that read string and integers from file, then copy

  • 0

I am writing a program that read string and integers from file, then copy the data and write to another file. Data entries should be separated by a space.

My input should and output should follow the following format, the first two set of numbers are string while the others are integers:

123123 242323 09 08 06 44

I get Exception in thread “main” java.util.NoSuchElementException when I run my code, I do not know why

import java.util.Scanner;
import java.io.*;

public class Billing {



    public static void main(String[] args)  throws IOException  {

        //define the variables


        String callingnumber;
        String callednumber;
        String line;
        int startinghour;
        int startingminute;
        int endinghour;
        int endingminute;


        //open input and output files
        FileReader freader = new FileReader("BillingData.txt");
        BufferedReader inFile = new BufferedReader(freader);


        FileWriter fwriter = new FileWriter("BillingOutput.txt");
        PrintWriter outFile = new PrintWriter (fwriter);

        // set space between the numbers
         line=inFile.readLine();
         while(line!=null)
         {
             //creat a scanner to use space between the numbers
             Scanner space = new Scanner(line).useDelimiter(" ");


             callingnumber=space.next();
             callednumber=space.next();
             startinghour=space.nextInt();
             startingminute=space.nextInt();
             endinghour=space.nextInt();
             endingminute=space.nextInt();



            // writing data to file
             outFile.printf("%s %s %d %d %d %d", callingnumber, callednumber,startinghour, startingminute, endinghour, endingminute);

             line=inFile.readLine();



         }//end while

         //close the files
         inFile.close();
         outFile.close();


    }//end of mine


}//end of class
  • 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-13T02:51:31+00:00Added an answer on June 13, 2026 at 2:51 am

    I suspect that the scanner has run out of data in the line – probably because there are less than 6 values in it. To avoid the error you should do something like this:

    if (space.hasNextInt()) {
        startingHour = space.nextInt();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program for an exercise that will read data from a file
I have to write a program that read from a file that contains the
Im writing a program that should read input via stdin, so I have the
I'm writing a small program in C that will read input from the console.
I am writing a program that will read lines from an infile using getline
I'm writing a program that will guess words taken from a big text file.
I am writing a small program that will read a plain ASCII text file
I am writing a program that needs to read in very large files (about
I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing a program that reads huge file (3x280 GB) and does a fitting

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.