Java IO stream (character stream) file open, read file, close file

Source: Internet
Author: User

Java IO stream (character stream)

File Open

Read file

Close File

//Open File//Read File contents//Close FileImportJava.io.*; Public classindex{ Public Static voidMain (string[] args)throwsexception{//Open File//character Stream mode open//Character streams are read by one character at a timeFileReader WJ =NewFileReader ("D:/java/kj/javanew/src/index.java"); //byte stream mode open//byte stream is read at a time//FileInputStream WJ = new FileInputStream ("D:/java/kj/javanew/src/index.java"); //Read File contents        intAa//This must be defined as shaping, and Java specifies that the return value of the Read () method in Io is shapedAA = Wj.read ();//read one characterString content = "";  while(Aa!= (-1)) {//The ASCII code is a number starting at 0, and only nothing will return-1Content + = (Char) AA; AA= Wj.read ();//Continue reading one character        }                //Output File ContentsSystem.out.println ("File content is:");                System.out.print (content); //Close FileWj.close (); }}

Java IO stream (character stream) file open, read file, close file

Related Article

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.