Java_FileInputStream_读一个文件
生活随笔
收集整理的這篇文章主要介紹了
Java_FileInputStream_读一个文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Java_FileInputStream_讀一個文件
代碼:
package demo01;import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException;public class FileInputStreamTest01 {public static void main(String[] args) {FileInputStream fis = null;try {//默認路徑為當前工程路徑fis = new FileInputStream("src/demo01/temp01");byte[] bytes = new byte[4];//低級寫法/*while (true){int readCount = fis.read(bytes);if (readCount == -1){break;}System.out.print(new String(bytes,0,readCount));}*///高級寫法int readCount = 0;while ((readCount = fis.read(bytes)) != -1){System.out.print(new String(bytes,0,readCount));}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}} }運行結果:
總結
以上是生活随笔為你收集整理的Java_FileInputStream_读一个文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spss多元非线性曲线拟合_快速掌握SP
- 下一篇: java美元兑换,(Java实现) 美元