Read a file from disk to memory, and then print to the console

Source: Internet
Author: User

public class Work3 {

public static void Main (string[] args) throws IOException {

GetFile ();

}


By creating buffers and loops to read
public static void GetFile () throws ioexception{


1. Find the target file
File File = new file ("C:\\abcd\\12.5.txt");


2. Establishing a Channel
FileInputStream FileInputStream = new FileInputStream (file);


3. Creating buffers
Byte[] B = new byte[1024];


4. Reading data
int count = 0;
while ((count = Fileinputstream.read (b))!=-1) {
System.out.println (New String (B,0,count));
It means that the elements in array B are paid to string,0, which is the offset, starting from the No. 0 of the array.
}
Fileinputstream.close ();
}

}

Read a file from disk to memory, and then print 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.