码迷,mamicode.com
首页 > 编程语言 > 详细

Java IO操作

时间:2019-09-12 00:01:38      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:pre   file   throw   static   final   java   char   oid   hello   

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();
                }
            }
        }
    }

 

Java IO操作

标签:pre   file   throw   static   final   java   char   oid   hello   

原文地址:https://www.cnblogs.com/kikyoqiang/p/11509308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!