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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:22:55+00:00 2026-06-01T09:22:55+00:00

import java.io.*; import java.util.*; public class Readfilm { public static void main(String[] args) throws

  • 0
 import java.io.*;
    import java.util.*;

    public class Readfilm {

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

        ArrayList films = new ArrayList();
        File file = new File("filmList.txt");
        try {
            Scanner scanner = new Scanner(file);

            while (scanner.hasNext())
            {
                String filmName = scanner.next();
                System.out.println(filmName);
            }
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
    }}

Above is the code I’m currently attempting to use, it compiles fine, then I get a runtime error of:

java.util.NoSuchElementException  
    at java.util.Scanner.throwFor(Scanner.java:907)  
    at java.util.Scanner.next(Scanner.java:1416)  
    at Readfilm.main(Readfilm.java:15)  

I’ve googled the error and not had anything that helped (I only googled the first 3 lines of the error)

Basically, the program I’m writing is part of a bigger program. This part is to get information from a text file which is written like this:

Film one / 1.5
Film two / 1.3
Film Three / 2.1
Film Four / 4.0

with the text being the film title, and the float being the duration of the film (which will have 20 minutes added to it (For adverts) and then will be rounded up to the nearest int)

Moving on, the program is then to put the information in an array so it can be accessed & modified easily from the program, and then written back to the file.

My issues are:

I get a run time error currently, not a clue how to fix? (at the moment I’m just trying to read each line, and store it in an array, as a base to the rest of the program) Can anyone point me in the right direction?

I have no idea how to have a split at “/” I think it’s something like .split(“/”)?

Any help would be greatly appreciated!

Zack.

  • 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-01T09:22:57+00:00Added an answer on June 1, 2026 at 9:22 am

    Your code is working but it reads just one line .You can use bufferedReader here is an example

    import java.io.*;
    class FileRead 
    {
     public static void main(String args[])
      {
      try{
      // Open the file that is the first 
      // command line parameter
      FileInputStream fstream = new FileInputStream("textfile.txt");
      // Get the object of DataInputStream
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
      //Read File Line By Line
      while ((strLine = br.readLine()) != null)   {
      // Print the content on the console
      System.out.println (strLine);
      }
      //Close the input stream
      in.close();
        }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
      }
      }
    }

    And here is an split example

    class StringSplitExample {
            public static void main(String[] args) {
                    String st = "Hello_World";
                    String str[] = st.split("_");
                    for (int i = 0; i < str.length; i++) {
                            System.out.println(str[i]);
                    }
            }
    }

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

Sidebar

Related Questions

import java.util.ArrayList; import java.util.Random; public class Generator{ //9352141NTBG1223 public static void main(String[] args) {
package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
import java.util.*; public class Test { public static void main(String[] args) { List db
import java.util.Scanner; public class Main extends Hashmap{ public static void main(String[] args) { Hashmap
import java.util.*; public class oddNumbers { public static void main(String[] args) { System.out.println(enter two
import java.util.Scanner; public class EP55Out { public static void main(String[] args) { Scanner in
import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) {
import java.util.scanner; import javax.swing.JOptionPane; public class FirstHomeJavaApplet{ public static void main(String[] args){ int num1=2;
import java.util.*; public class Test { public static void main(String[] args) { Map<String,String> map
Given: import java.util.*; public class Quest { public static void main(String[] args) { String[]

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.