Java IO操作

111

    private static void FileInputStream() throws IOException {
        FileInputStream fis = new FileInputStream("fos.txt");
        // int by = fis.read();
        // System.out.println(by);
        // System.out.println((char) by);
        //
        // by = fis.read();
        // System.out.println(by);
        // System.out.println((char) by);
        // int by = fis.read();
        // while (by != -1) {
        //     System.out.print((char) by);
        //     by = fis.read();
        // }
        int by;
        while ((by = fis.read()) != -1) {
            System.out.println((char) by);
        }
        fis.close();
    }

    private static void FileOutputStream() {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("fos.txt", true);
            for (int i = 0; i < 5; i++) {
                fos.write("hello".getBytes());
                fos.write("
".getBytes());
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
原文地址:https://www.cnblogs.com/kikyoqiang/p/11509308.html