Results 1 to 8 of 8
Thread: How to use Scanner ?
- 08-10-2011, 12:19 PM #1
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
How to use Scanner ?
Hi,
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 outJava Code:Scanner scan = new Scanner(new File("textfile.txt"));
Regards
Sandeep
- 08-10-2011, 12:23 PM #2
what type of error you got?
ThanX
Rj
- 08-10-2011, 12:24 PM #3
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
Hi RJ
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
Sandeep
- 08-10-2011, 12:29 PM #4
try getAbsolutePath() in File class
then convert to string and pass the path...ThanX
Rj
- 08-10-2011, 12:45 PM #5
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
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.
Sandeep
- 08-10-2011, 12:51 PM #6
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..ThanX
Rj
- 08-10-2011, 12:51 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,605
- Blog Entries
- 7
- Rep Power
- 17
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:
But then again, what should your application do if its working directory changes? I leave that up to you.Java Code:System.out.println(System.getProperty("user.dir"));
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 08-10-2011, 01:29 PM #8
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
Similar Threads
-
Using scanner for CSV
By getName() in forum Advanced JavaReplies: 7Last Post: 06-20-2010, 04:33 PM -
Help With Scanner
By jtmoney0511 in forum New To JavaReplies: 10Last Post: 10-12-2009, 11:24 PM -
Need help with scanner.
By mainy in forum New To JavaReplies: 3Last Post: 07-28-2009, 02:11 PM -
Scanner
By choko in forum New To JavaReplies: 10Last Post: 01-24-2009, 03:37 PM -
need help with scanner
By whiterex in forum New To JavaReplies: 1Last Post: 04-22-2008, 01:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks