src/share/classes/java/util/Scanner.java

Print this page




 652         throws FileNotFoundException
 653     {
 654         this((ReadableByteChannel)(new FileInputStream(source).getChannel()));
 655     }
 656 
 657     /**
 658      * Constructs a new <code>Scanner</code> that produces values scanned
 659      * from the specified file. Bytes from the file are converted into
 660      * characters using the specified charset.
 661      *
 662      * @param  source A file to be scanned
 663      * @param charsetName The encoding type used to convert bytes from the file
 664      *        into characters to be scanned
 665      * @throws FileNotFoundException if source is not found
 666      * @throws IllegalArgumentException if the specified encoding is
 667      *         not found
 668      */
 669     public Scanner(File source, String charsetName)
 670         throws FileNotFoundException
 671     {
 672         this((ReadableByteChannel)(new FileInputStream(source).getChannel()),

 673              charsetName);
 674     }
 675 














 676     /**
 677      * Constructs a new <code>Scanner</code> that produces values scanned
 678      * from the specified file. Bytes from the file are converted into
 679      * characters using the underlying platform's
 680      * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
 681      *
 682      * @param   source
 683      *          A file to be scanned
 684      * @throws  IOException
 685      *          if an I/O error occurs opening source
 686      *
 687      * @since   1.7
 688      */
 689     public Scanner(FileRef source)
 690         throws IOException
 691     {
 692         this(source.newInputStream());
 693     }
 694 
 695     /**




 652         throws FileNotFoundException
 653     {
 654         this((ReadableByteChannel)(new FileInputStream(source).getChannel()));
 655     }
 656 
 657     /**
 658      * Constructs a new <code>Scanner</code> that produces values scanned
 659      * from the specified file. Bytes from the file are converted into
 660      * characters using the specified charset.
 661      *
 662      * @param  source A file to be scanned
 663      * @param charsetName The encoding type used to convert bytes from the file
 664      *        into characters to be scanned
 665      * @throws FileNotFoundException if source is not found
 666      * @throws IllegalArgumentException if the specified encoding is
 667      *         not found
 668      */
 669     public Scanner(File source, String charsetName)
 670         throws FileNotFoundException
 671     {
 672         this(verifyCharsetName(charsetName),
 673              (ReadableByteChannel)(new FileInputStream(source).getChannel()),
 674              charsetName);
 675     }
 676     
 677     /**
 678      * Private constructor used so that invokers can verify the charsetName
 679      * before creating the FileInputStream.
 680      */
 681     private Scanner(Void unused, ReadableByteChannel source, String charsetName) {
 682         this(source, charsetName);
 683     }
 684 
 685     private static Void verifyCharsetName(String charsetName) {
 686         if (!Charset.isSupported(charsetName))
 687             throw new IllegalArgumentException(charsetName);
 688         return null;
 689     }
 690 
 691     /**
 692      * Constructs a new <code>Scanner</code> that produces values scanned
 693      * from the specified file. Bytes from the file are converted into
 694      * characters using the underlying platform's
 695      * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
 696      *
 697      * @param   source
 698      *          A file to be scanned
 699      * @throws  IOException
 700      *          if an I/O error occurs opening source
 701      *
 702      * @since   1.7
 703      */
 704     public Scanner(FileRef source)
 705         throws IOException
 706     {
 707         this(source.newInputStream());
 708     }
 709 
 710     /**