Java Reference
In-Depth Information
scanner
=
new Scanner (file);
}
catch (FileNotFoundException e)
{
System.out.println ("File not found!");
// Stop program if no file found
System.exit (0);
}
try {
// Skip tokens until the boolean is found.
while (true) {
if (scanner.hasNextBoolean ()) break;
scanner.next ();
}
System.out.printf ("Skip strings at start of%s%n",
file.toString ());
System.out.printf (
"
and then read the primitive type values:%n%n
"
);
// Read and print the boolean
System.out.printf(
"
boolean
=
%9b %n
"
,
scanner.nextBoolean ());
// and then the set of numbers
System.out.printf ("int = %9d %n",
scanner.nextInt ());
System.out.printf ("int = %9d %n",
scanner.nextInt ());
System.out.printf ("int = %9d %n",
scanner.nextInt ());
System.out.printf ("long = %9d %n",
scanner.nextLong ());
System.out.printf ("float = %9.1f %n",
scanner.nextFloat ());
System.out.printf ("double = %9.1e %n",
scanner.nextFloat ());
}
catch (InputMismatchException e)
{
System.out.println (
"
Mismatch exception:
"
+ e);
}
}
// main
}
// class ScanFileApp
Search WWH ::
Custom Search