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("\r\n".getBytes());
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

 

posted @ 2019-09-11 22:45  一只桔子2233  阅读(93)  评论(0编辑  收藏  举报