飞狐爷

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

输出流:

OutputStream()

 

import java.io.File;
import java.io.OutputStream;
import java.io.FileOutputStream;

public class Hello{
    public static void main(String args[]) throws Exception{
        File file = new File("D:" + File.separator + "A_test" + File.separator + "my.txt");
        if(!file.getParentFile().exists()){
            file.getParentFile().mkdirs();
        }
        OutputStream os = new FileOutputStream(file);
        String msg = "hello world, my is OutputStream()";
        byte data[] = msg.getBytes();
        os.write(data);
        os.close();
    }
}

 输入流:

Inputstream()

 

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class Hello{
    public static void main(String args[]) throws Exception{
        File file = new File("D:" + File.separator + "A_test" + File.separator + "my.txt");
        if(file.exists() && file.isFile()){
            InputStream input = new FileInputStream(file);
            byte data[] = new byte[1024] ;
            int len = input.read(data) ;
            System.out.println(new String(data,0,len));
        }
    }
}

 

posted on 2016-08-25 20:32  飞狐爷  阅读(228)  评论(0编辑  收藏  举报