Reading in a file.
Ive been given this code as part of a lexical analyser for which i will be coding a syntax analyser - however the file the lexical analyser will be reading will come throught this code:
public static void main(String[] args) throws IOException
{
BufferedReader din = new BufferedReader(new InputStreamReader(System.in)) ;
System.err.print("file? ") ;
System.err.flush() ;
String fileName = din.readLine().trim() ;
LexicalAnalyser lex = new LexicalAnalyser(fileName) ;
} // end of class LexicalAnalyser
The thing is - where is the path name meant to go? It works by replacing fileName however im not so sure why my lecturer has coded the bufferedreader and inputstreamreader :S
MrScruff
Junior Poster in Training
89 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
You type in the filename and path from the console when you run th code. Isn't that what System.in is? I don't know I've never used it.
Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
yup. What I find rather troublesome is that he uses System.err for non-error output...
It would be much preferred to read the inputfile through the commandline.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337