Java IO流 之 FileInputStream

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

package com.io;

import java.io.*;

public class TestInputStream2
{
    public static void main(String[] args)
    {
        try
        {
            //建立了跟文件 english.txt 的连接
            InputStream is=new FileInputStream(new File("res/english.txt"));
            //每次 从文件 只读一个字符, 返回值 就是读到的 那个字符的 ACSII 的int 整数类型值
            //当文件下一个还存在字符继续读, 否则读到了文件末尾 返回 -1
            int l;
            while((l=is.read())!=-1)
            {
                System.out.println((char)l);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}





english.txt 内容 

Provides classes that are fundamental to the design of the Java programming language.

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

猜你喜欢

转载自www.cnblogs.com/verejava/p/9227199.html