怎么利用I/O来读取文件,,,体现读取超时求简单程序!!!

解决方案 »

  1.   

    import java.io.*;
    public class Test {
    public static void main(String[] args) {
    FileInputStream n = null;
    StringBuffer s = new StringBuffer();
    int temp = 0;
    try{
    n = new FileInputStream("f://a.txt");

    while((temp = n.read()) != -1){
    s.append((char)temp);
    } //这种方法效率会高一些。
    /*byte b[] = new byte[1024];
    while((temp=n.read(b))!=-1){
    s.append(new String(b,0,temp));
    }*/
    System.out.print(s.toString());
    }
    catch(Exception e){
    e.printStackTrace();
    }
    finally {
    try{
    n.close();
    }catch(IOException e){
    e.printStackTrace();
    }
    }
    }
    }