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