Java IO stream FileInputStream Read file

Source: Internet
Author: User

http://www.verejava.com/?id=1699461971466

package com.io;import java.io.*;public class TestInputStream{    public static void main(String[] args)    {        InputStream is=null;        try        {            //建立了跟文件 english.txt 的连接            is=new FileInputStream(new File("res/english.txt"));            //读取数据            byte[] data=new byte[1024];            //将文件中的数据 全部读取到 data 字节数组里面            is.read(data);            //输出从文件读取的数据            System.out.println(new String(data));                    }        catch (Exception e)        {            e.printStackTrace();        }        finally        {            //关闭文件            try            {                is.close();            }            catch (IOException e)            {                e.printStackTrace();            }        }    }}english.txt 内容 Provides classes that are fundamental to the design of the Java programming language.

http://www.verejava.com/?id=1699461971466

Java io stream fileinputstream Read 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.