TXT

printFileTest

By Leslie Jones,2014-12-08 22:11
7 views 0
printFileTest

    package com.bluedot.advancedjava.day01;

//打印出来一个文件

    import java.io.File;

    import java.io.FileInputStream;

    import java.io.FileNotFoundException;

    import java.io.IOException;

public class printFileTest {

     public static void main(String[] args) throws IOException {

     File file = new File("D:/test/java/test1.txt");

     FileInputStream fis = new FileInputStream(file);

     byte[] buf = new byte[160*1024];

     int i = 0;

     while((i=fis.read(buf))>0){//fis全部读入buf

     System.out.println(new String(buf,0,i));//String(buf,0,i),等价于复制

     }}}

     }

     }

Report this document

For any questions or suggestions please email
cust-service@docsford.com