How to use Scanner ?
i have used Scanner to read a textfile and input data into a table
when i run the jar file through Netbeans it works fine, but when i manually go and run this from the My Documents (Where my jar file is generated), it throws an error, i think may be we are suppose to give path, if so how can i assign? and also i wont be knowing the path, it keeps changing, please help me out
Scanner scan = new Scanner(new File("textfile.txt"));
what type of error you got?
i got my error msg what i had told to display.
All i want is how to set dynamic path for that textfile, so that the application reads that file without any problem
try getAbsolutePath() in File class
then convert to string and pass the path...
Actually tell me where should we keep the Textfile so that application always reads it? i mean which path it should be placed within the generated file.
the jar file and the text file (you are going to read) always put in the same folder..
then only the scanner will read the text file.. if you put the txt file in other location it dont work..
Put this near the start of your code and it'll tell you where your application runs and so where you are supposed to put your file:
Originally Posted by sandeep43
But then again, what should your application do if its working directory changes? I leave that up to you.
both of u rock, it worked awesome.
thanks and regards