java - How to make a File class input case sensitive for the file name? -
i have working application here reads text file using file class after prompting user file name input. however, have make case-sensitive means if user inputs zombie.txt, there filenotfoundexception thrown although actual file name zombie.txt. question how correct application make so?
additionally, i'm still newbie programming etc, suggestions or advices shorten code appreciated. ;)
thanks in advance!
import java.util.scanner; import java.io.*; class filereadingexercise { public static void main (string [] args) { scanner userinput = new scanner(system.in); scanner fileinput = null; { try { system.out.println("please enter name of file or type quit finish"); string = userinput.nextline(); if(a.equals("quit")) { system.exit(0); } fileinput = new scanner(new file(a)); //inline expression } catch (filenotfoundexception e) { system.out.println("error - file not exist"); //read document there more } } while (fileinput == null); while(fileinput.hasnext()) { string first = fileinput.nextline(); system.out.println(first); } fileinput.close(); } }
- retrieve filenames , add them in
arraylist. - use
containsmethod of arraylist checking user's file name. contains method case sensative.
Comments
Post a Comment