java学习(148):三个参数的输入流
生活随笔
收集整理的這篇文章主要介紹了
java学习(148):三个参数的输入流
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//3個(gè)參數(shù)讀取二進(jìn)制文件
import java.io.*;public class FileManage {public static void readBitFile(String filename){//1建立目標(biāo)要讀取的文件對象File file=new File( filename );//2基于目標(biāo)對象建立輸入流InputStream in=null;if(file.exists()){//如果文件存在,創(chuàng)建文件輸入流System.out.println( "文件的長度"+file.length() );try {in = new FileInputStream( file );//使用子類inputstream輸入流int count = 0;//讀取的字節(jié)數(shù)byte []bys=new byte[124];//臨時(shí)存儲(chǔ)讀取的二進(jìn)制數(shù)據(jù)while((count=in.read(bys,0,bys.length))!=-1) {String s=new String(bys,0,count);System.out.print( s);}}catch (FileNotFoundException e){e.printStackTrace();}catch (IOException e){e.printStackTrace();}finally {try {in.close();System.out.println( "關(guān)閉成功" );}catch (IOException e){e.printStackTrace();}}}//讀取文件內(nèi)容//關(guān)閉輸入流}
}
測試類
public class test93 {public static void main(String[] args){FileManage.readBitFile( "e:/1.txt" );} }運(yùn)行結(jié)果
總結(jié)
以上是生活随笔為你收集整理的java学习(148):三个参数的输入流的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言字符串逆置,字符串逆置
- 下一篇: 序列号列表