Question : How do I use a user input filename and then read line by line

I am really new to Java and am feeling quite challenged at the moment!  :)

I need to allow the user to input the filename to read from, so I'm using a scanner:

 try{
            Scanner in = new Scanner(System.in);
            System.out.print("Enter name of input file: ");
            Scanner input=new Scanner(new FileReader(in.nextLine()));

            if(!input.hasNext())
            {System.out.println("File Empty - aborting");
            System.exit(0);}
            while (input.hasNextLine())
            {

After reading the input file, I need to count the characters and output the number of chars per line into a text file (so the number of lines in the source file will match the output file).  I think I need to use BufferedInputStream to read it line by line, but I'm not sure how to use it with the scanner, or if what I have above is good enough.  All the examples I have found used a static file name with BufferedInputStream.

Thanks!!!

Answer : How do I use a user input filename and then read line by line

no need for a scanner, see the following for how to read the file

http://helpdesk.objects.com.au/java/how-do-i-read-a-text-file-line-by-line

Random Solutions  
 
programming4us programming4us