⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileinputstreamdemo.java

📁 用java对文件操作的一些代码(包括文件读取
💻 JAVA
字号:
package java_io;import java.io.*;/** * <p>Title: 从磁盘文件中读取字节数据</p> */public class FileInputStreamDemo {    /**     * FileInputStream从磁盘文件中读取字节数据的输入类。     * FileInputStream(File file)根据File类的对象创建一个字节输入流的对象     * FileInputStream(String name)根据字符串创建一个字节输入流的对象     * 这个字符串一般用来表示文件路径或名称。     * @param args     */    public static void main(String[] args) {        try {            File file = new File("testFile/data.txt");            FileInputStream fin = new FileInputStream(file);            if (file.isFile()) {                System.out.println("File Location : " + file.getAbsolutePath());                if (file.canRead()) {                    System.out.println("File can be Read.");                    try {                        while (fin.available() > 0) {//判断文件是否读完                            System.out.print((char) fin.read());                        }                        System.out.println();                        fin.close();//关闭文件输入流                    } catch (IOException e) {                        e.printStackTrace();                    }                } else {                    System.out.println("File can not be Read.");                }            } else {                System.out.println("This is not a file.");            }        } catch (FileNotFoundException e) {            e.printStackTrace();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -