演示FileInputStream案例演示
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                演示FileInputStream案例演示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            /*** 演示FileInputStream*1:把文件讀入到計算機內存中*/package com.test2;import java.io.*;public class Demo11_2 {
/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubFile f=new File("d:\\123.java");FileInputStream fis=null;//因為File沒有讀功能,所以需要一個InputStreamtry {fis=new FileInputStream(f);//定義一個字節數組byte []bytes=new byte[1024];//循環讀取int n=0;while( (n=fis.read(bytes))!=-1){//把字節數組中的內容轉換成字符串String s=new String(bytes, 0, n);//輸出字符串中的內容System.out.println(s);}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{//關閉文件流必須關閉try {fis.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
}
                        
                        
                        /*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubFile f=new File("d:\\123.java");FileInputStream fis=null;//因為File沒有讀功能,所以需要一個InputStreamtry {fis=new FileInputStream(f);//定義一個字節數組byte []bytes=new byte[1024];//循環讀取int n=0;while( (n=fis.read(bytes))!=-1){//把字節數組中的內容轉換成字符串String s=new String(bytes, 0, n);//輸出字符串中的內容System.out.println(s);}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{//關閉文件流必須關閉try {fis.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
}
轉載于:https://www.cnblogs.com/toge/p/6114726.html
總結
以上是生活随笔為你收集整理的演示FileInputStream案例演示的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Spring MVC 启动
 - 下一篇: 日产在日本召回超 48 万辆电动汽车,涉