Question

Im trying to take a file name(location) from a command line input and then read the contents of that file.

public class Beekeeper {

    public static void main(String[] args) {

        Garden garden = new Garden();
        System.out.println("Enter File Name Please");
        Scanner cmdReader = new Scanner(System.in);
        String cmdInput = cmdReader.next();
        fileReader(cmdInput);
        //code removed
    }

    protected static void fileReader(FileInputStream fileName) {
        FileInputStream configFile = fileName;
        Scanner configScanner = new Scanner(configFile);
    //code removed
    }
}

Currently it isnt working as im trying to put a string as a parameter that is ment to be a FileInputStream but I'm trying to find a way to convert that string to a FileInputStream, or to get the FileInputStream strait from the cmd input.

Thanks for any help

Était-ce utile?

La solution

I think I got your problem. You are passing string which is a file path. You have to pass instace of FileInputStream

  fileReader(new FileInputStream (cmdReader));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top