FileInputStream读取文件

来源:互联网 发布:c语言教程谭浩强pdf 编辑:程序博客网 时间:2024/06/07 12:17

/** *//**读文件
* @param path
* @return
* @throws IOException
*/
public String FileInputStreamDemo(String path) throws IOException...{  
    File file=new File(path);  
    if(!file.exists()||file.isDirectory())  
        throw new FileNotFoundException();  
    FileInputStream fis=new FileInputStream(file);  
    byte[] buf = new byte[1024];  
    StringBuffer sb=new StringBuffer();  
    while((fis.read(buf))!=-1)...{  
        sb.append(new String(buf));      
        buf=new byte[1024];//重新生成,避免和上次读取的数据重复  
    }  
    return sb.toString();  
}

原创粉丝点击