博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FileInputStream实现读取文件内容并输出到屏幕上
阅读量:4327 次
发布时间:2019-06-06

本文共 979 字,大约阅读时间需要 3 分钟。

java输入输出流是站在程序的角度来说的。从文件中读取数据用输入流,向文件中写数据用输出流。

package com.janson.day20180827;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;public class TestFileInputStream {    public static void main(String[] args) {        FileInputStream in = null;        int f = 0;        try {            in = new FileInputStream(System.getProperty("user.dir") + "\\src\\com\\janson\\day20180827\\TestFileInputStream.java");        }catch (FileNotFoundException e) {            e.printStackTrace();            System.out.println("找不到指定文件");            System.exit(-1);        }        try {            long num =0L;            while ((f=in.read()) != -1) {                System.out.print((char)f);                num ++;            }            System.out.println("一共读取了"+ num + "个字节");        }catch (IOException e) {            System.out.println("文件读取错误");            System.exit(-1);        }    }}

 

转载于:https://www.cnblogs.com/janson071/p/9605363.html

你可能感兴趣的文章
CRC码计算及校验原理的最通俗诠释
查看>>
QTcpSocket的连续发送数据和连续接收数据
查看>>
使用Gitbook来编写你的Api文档
查看>>
Python XML解析(转载)
查看>>
jquery扩展 $.fn
查看>>
tomcat 多实例的Sys V风格脚本
查看>>
程序员如何讲清楚技术方案
查看>>
MapReduce-实践1
查看>>
UVa 815 - Flooded!
查看>>
jQuery基础--选择器
查看>>
减小服务器负担,Apache启用mod_expires模块
查看>>
20.Mybatis之逆向工程
查看>>
mysql 中时间和日期函数应用
查看>>
自动化测试-selenium初始化Driver参考
查看>>
mybatis使用collection查询集合属性规则
查看>>
linux查看文件的编码格式的方法 set fileencoding PYTHON
查看>>
Git 问题:SSL certificate problem: self signed certificate
查看>>
安全测试
查看>>
作业代码
查看>>
网络抓取功能实现 将获取的结果进行过滤并写入到TXT文档中
查看>>