| | |
how to use scanner correctly
![]() |
•
•
Join Date: Oct 2004
Posts: 26
Reputation:
Solved Threads: 0
how do i declare a scanner object, filescan publicly so that i may use filescan in varios functions
i found this statement in a forum---->
private static Scanner scanner = new Scanner (1 3 4 4");
when I modified it to----->
public static Scanner filescan = new Scanner(new File("inputdata.txt"));
//declared in the main
i get the following error message
Illegal modifier for parameter scanner; only final is permitted
Thank you guys
i found this statement in a forum---->
private static Scanner scanner = new Scanner (1 3 4 4");
when I modified it to----->
public static Scanner filescan = new Scanner(new File("inputdata.txt"));
//declared in the main
i get the following error message
Illegal modifier for parameter scanner; only final is permitted
Thank you guys
Yes ..
it has to be simply
FYI :
Scanner is from - java.util.Scanner
A simple text scanner which can parse primitive types and strings using regular expressions.
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.
For example, this code allows a user to read a number from System.in:
it has to be simply
•
•
•
•
Scanner filescan = new Scanner(new File("inputdata.txt"));
Scanner is from - java.util.Scanner
A simple text scanner which can parse primitive types and strings using regular expressions.
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.
For example, this code allows a user to read a number from System.in:
•
•
•
•
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
"The most important single aspect of software development is to be clear about what you are trying to build." - Bjarne Stroustrup
•
•
Join Date: Oct 2004
Posts: 26
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
public class praogram1 { Scanner scanner = new Scanner (new File ("t.txt")); public static void main(String[] args) { } }
ok..im tryin to define it at the class level and i run into this issue now. How do i throw an IOException at this level
Default constructor cannot handle exception type FileNotFoundException thrown by implicit super constructor. Must define an explicit constructor
Java Syntax (Toggle Plain Text)
public class Program1 { Scanner scanner = null; public Program1(){ try { scanner = new Scanner(new File("t.txt")); } catch (FileNotFoundException fe){ fe.printStackTrace(); } } public static void main(String[] args) { } }
![]() |
Similar Threads
- Homework help (Java)
- Port Scanner in C++ (C++)
- First post, need help, so frustrated (Viruses, Spyware and other Nasties)
- SpySheriff infection.. (Viruses, Spyware and other Nasties)
- XP and Scanmaker E3 - keeps finding it! (Windows NT / 2000 / XP)
- TODO: <Product Name>, Aurora Popup and an Automatic dialer problems... (Viruses, Spyware and other Nasties)
- Nic Card Disconnecting/Reconnecting (Networking Hardware Configuration)
- jrsuellen's Hijack this log (Viruses, Spyware and other Nasties)
- Word (and other utilities) don't load correctly (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: How to Store two different class objects in Same array. - new to Java ..Need Help
- Next Thread: help!
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






