Can anyone pointed out what is wrong with this code. I got an annoying error something with Scanner method.

    import java.util.*;
    //import java.lang.System.*;

    public class cTedit implements ICommand{

        public void Execute() {
            InputStream istream;
            OutputStream ostream = null;
            int x;
            final int EOF = -1;
            istream =;

            Scanner scan = new Scanner(;
            System.out.println("Enter the name of the file");
            String filename = scan.nextLine();

            File outFile = new File(cShell.Currentpath+"\\"+filename);
            System.out.println("Edit a file - Press Ctrl+z to end");

            try {

                ostream = new FileOutputStream(outFile);
                while((x =!= EOF)

            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println("Error: " + e.getMessage());
                catch(IOException e)
                    System.out.println("File did not close");

I also have another class where the main is:

    import java.util.HashMap;
    import java.util.Scanner;

    public class cShell {

            static String Currentpath="C:\\";
            public String Current = Currentpath;

            static HashMap<String, ICommand> myhashData=new HashMap<String, ICommand>();

            public static void main(String[] args)

                myhashData.put("ls", new cLS());
                myhashData.put("gd", new cGD());
                myhashData.put("md", new cMD());
                myhashData.put("rnd", new cRND());
                myhashData.put("del", new cDEL());
                myhashData.put("hd", new cHD());
                myhashData.put("uhd", new cUHD());
                myhashData.put("ltf", new cITF());
                myhashData.put("nbc", new cNBC());
                myhashData.put("gdb", new cGDB());
                myhashData.put("Tedit", new cTedit());

                        System.out.print(Currentpath+"> ");

                        Scanner scan = new Scanner(;
                        String Input = scan.nextLine().trim();


                            ICommand myCommand=myhashData.get(Input);
                            System.out.println("Invalid Command");


Edited 2 Years Ago by DawnofanewEra: for clarification of question

This is the complete error message...

Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at cShell.main(

"an annoying error something with Scanner method"
It would be a lot more helpful if you gave us the exact complete error message, including the all-important line number(s)

(edit: this post should have appeared before the previous one!)

Edited 2 Years Ago by JamesCherrill

Scanners are the source of a lot of DaniWeb threads - they were intended to be simple, but too often don't work like you expect.
I suggest that since you are not using Scanner's parsing, why not just open a BufferedReader and use its readLine() method - far more predictable

you should have to try this:

InputStreamReader isr = new InputStreamReader(;
BufferedReader br = new BufferedReader(isr);

just import*;


This article has been dead for over six months. Start a new discussion instead.