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

Print this page




 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      * {@note new}
 678      * Constructs a new <code>Scanner</code> that produces values scanned
 679      * from the specified file. Bytes from the file are converted into
 680      * characters using the underlying platform's
 681      * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
 682      *
 683      * @param   source
 684      *          A file to be scanned
 685      * @throws  IOException
 686      *          if an I/O error occurs opening source
 687      *
 688      * @since   1.7
 689      */
 690     public Scanner(FileRef source)
 691         throws IOException
 692     {
 693         this(source.newInputStream());
 694     }
 695 
 696     /**
 697      * {@note new}
 698      * Constructs a new <code>Scanner</code> that produces values scanned
 699      * from the specified file. Bytes from the file are converted into
 700      * characters using the specified charset.
 701      *
 702      * @param   source
 703      *          A file to be scanned
 704      * @param   charsetName
 705      *          The encoding type used to convert bytes from the file
 706      *          into characters to be scanned
 707      * @throws  IOException
 708      *          if an I/O error occurs opening source
 709      * @throws  IllegalArgumentException
 710      *          if the specified encoding is not found
 711      * @since   1.7
 712      */
 713     public Scanner(FileRef source, String charsetName)
 714         throws IOException
 715     {
 716         this(source.newInputStream(), charsetName);
 717     }




 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     /**

 696      * Constructs a new <code>Scanner</code> that produces values scanned
 697      * from the specified file. Bytes from the file are converted into
 698      * characters using the specified charset.
 699      *
 700      * @param   source
 701      *          A file to be scanned
 702      * @param   charsetName
 703      *          The encoding type used to convert bytes from the file
 704      *          into characters to be scanned
 705      * @throws  IOException
 706      *          if an I/O error occurs opening source
 707      * @throws  IllegalArgumentException
 708      *          if the specified encoding is not found
 709      * @since   1.7
 710      */
 711     public Scanner(FileRef source, String charsetName)
 712         throws IOException
 713     {
 714         this(source.newInputStream(), charsetName);
 715     }