经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » Java相关 » Java » 查看文章
java中讲讲FileInputStream的用法,举例? - 马克-to-win
来源:cnblogs  作者:马克-to-win  时间:2018/9/25 20:53:54  对本文有异议

2.2 FileInputStream的用法 (视频下载) (全部书籍)

FileInputStream是InputStream的继承类,从字面上就可看出,它的主要功能就是能从磁盘上读入文件。read方法会一个一个字节的从磁盘往回读数据。

例:2.2.1

import java.io.*;
public class TestMark_to_win {
    public static void main(String args[]) throws Exception {
        int size;
        FileInputStream f1 = new FileInputStream("c:/1.txt");
        /*Returns the number of bytes that can be read from this file input
stream without blocking.*/
        size = f1.available();
        for (int i = 0; i < size; i++) {
            /*Reads a byte of data from this input stream. This method blocks
if no input is yet available. Returns: the next byte of data, or
-1 if the end of the file is reached.*/
            System.out.println((char) f1.read());

        }

        int size2;
        FileInputStream f2 = new FileInputStream("c:/1.txt");
        size2 = f2.available();
        for (int i = 0; i < size2; i++) {
            /* you use the next statement, only int value can be printed out. */

 

详情黏贴以下网址在地址栏后请进:

http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner8_web.html#UsageOfFileInputStream

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号