字节流案例

package suanfahaonan;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;

public class Fileinput {

    public static void main(String[] args) throws IOException {
        //1,创建流
    FileInputStream fis=new FileInputStream("d:/hehe.txt");    
    byte[]b=new byte[fis.available()];
    fis.read(b);
    String str=new String(b);
System.out.println(str);
    //关闭流
    fis.close();
        
    }

}
package suanfahaonan;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;

public class Fileinput {

    public static void main(String[] args) throws IOException {
        //1,创建流
    FileInputStream fis=new FileInputStream("d:/test.txt");    
    BufferedInputStream bis=new BufferedInputStream(fis);
    byte[]b=new byte[bis.available()];
    bis.read(b);
    String str=new String(b,"UTF-8");
System.out.println(str);
    //关闭流
    bis.close();
        
    }

}

 

posted @ 2017-05-12 14:34  苏轼的红烧肉  阅读(204)  评论(0编辑  收藏  举报