Dark Horse Programmer--io--Read text output from a file to the console

Source: Internet
Author: User


read text from a file output to the console


Import Java.io.filenotfoundexception;import Java.io.filereader;import java.io.ioexception;//read the text in a file, output to the console// The character text is read, so you can use a character stream to manipulate public class Filereaderdemos {public static void main (string[] args) {//TODO auto-generated method s Tubfilereader fr = Null;try {fr = new FileReader ("c:\\users\\administrator\\desktop\\ Test folder \ \ new text document. txt");// Call the Read method output to the console int len = 0;try {while (len = Fr.read ())!=-1) {System.out.print (char) len);} catch (IOException e) {//TOD O auto-generated catch Blocke.printstacktrace ();}} catch (FileNotFoundException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Finally{try {fr.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}}}

To run the program:









Dark Horse Programmer--io--Read text output from a file to the console

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.