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

Java中FileOutputStream和FileInputStream使用例子

时间:2016-07-30 16:22:02      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
package a.ab;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class AC {
    int s = 0;

    public static void main(String[] args) {

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("D:\\DD\\ff.txt");
        } catch (FileNotFoundException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }
        try {
            fos.write("ddsfs山東高速費勝多負少v是vsdf".getBytes());
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        try {
            if (fos != null) {
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            FileInputStream fis = new FileInputStream("D:\\DD\\ff.txt");
            byte[] by = new byte[1024];
            int b = 0;
            try {
                while ((b = fis.read(by)) != -1) {
                    System.out.println(new String(by, 0, b));
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
View Code

 

Java中FileOutputStream和FileInputStream使用例子

标签:

原文地址:http://www.cnblogs.com/LYL-1314/p/5721077.html

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