So I'm having trouble formatting as a .txt file:
31,718 Philip Nenox 55.0 20.00 11528 Nancy Soldier 40,0 10.45 16783 John Connaught 30.5 10.00 10538 Peter Duncan 45.0 10.75 21O15 James Harold 32.0 10.50 61326 Harry Kuhn 25.0 12.30 Now I know there is purposively The errors inside .txt file, and that's where my hold (InputMismatchException n)
comes into play. I want to select any mismatch in the .txt file and be able to store it in another .txt file. The part I got stuck on is that I can not find this InputMismatchException
is found ...
I tried a for-loop , But a loop out of my try / hold method is continuing to see the .txt file successfully i setting int i = 0;
does not initially even start my program because the Arrayel arreremployee is of size null
? (What do I understand from Java)
This is my code (where is your Windows user name):
public class key {public static zero main (string [] Arg) {Aare list & lieutenant; Employee & gt; ArrEmployee = New Arrestist & lt; Employee & gt; (); // Array try for employee objects {scanner txtIn = new scanner (new file ("/ users / & lt; user & gt; / document / workspace / comp 249 - assignment 3 / src / payroll.txt")); While looping through the (// txtIn.hasNext ()) {// payroll.txt file and its employee has been working long time, employee numbers from employee numbers = txtIn.nextLong (); String employee name = txtIn.next (); String Last Name = txtIn.next (); Double hours worked = txtIn.nextDouble (); Double Hourly Access = txtIn.nextDouble (); ArrEmployee.add (new employee (employee number, employee name, last name, hours work, hourly)); }} Catch (FileNotExtensionE) {System.out.println ("File Payroll.TXT was not found."); } Hold (InputMismatchException N) {ifEremployee.get () getHourlyWage (). & Lt; 10.35) {println ("Minimum of Hourly Pay"); }}}}}
As your main error, I see that You have time to loop / catch blocks inside your line-reading attempt, and therefore there is no way to get back the loop when you run into an error.
Instead of:
- Yes, get your file first try / hold (File Not Access Exception ...) and enter your complete code inside it.
- Then do your InputMismatch for Exception while holding the loop inside.
- I myself, I want to use a scanner based on the file, say that the name is,
fileScanner
, - and my loop while loop While
(fileScanner.hasNextLine ())
- While the first row inside the loop, I >
- On the basis of the loop, I will create a second scanner. Received, possibly
lineScanner
, ie,scanner line scanner = new scanner (line);
- And I parse each token with this token, and inside Inside / Undo input input block . If this fails, then it should catch up, and you can handle it.
- As noted by Tom, if you are using Java 7, go with it. This way your scanners will be automatically shut down when you work with them.
In the pseudocode, try to find the file with the
and make the fileScanner scanner object while creating the file line from the next line of fileScanner next line fileScanner To use Try with resources, parse each token in line in line using line escanner line. ... Create an employee example with information received in the place of the erologic. Grab the input mismatch error Send the line to the end of the file while the file scanner does not have the next line is caught. File
No comments:
Post a Comment