read(bytes)

来源:互联网 发布:mac 查看文件夹权限 编辑:程序博客网 时间:2024/06/04 20:04
ServletContext context = event.getServletContext();
String filePath = context.getRealPath("/ch04/count.txt");
FileInputStream fis = null ;
BufferedInputStream bis = null ;
DataInputStream dis = null ;
StringBuffer sb = new StringBuffer() ;
byte[] bytes = new byte[1024];
try {
int c = 0 ;
fis = new FileInputStream(filePath) ;
dis = new DataInputStream(fis); 
// while((c=dis.read())!=-1)
// {
// sb.append((char)c);
// System.out.println((char)c+"*");
// }
while((c=dis.read(bytes))!=-1)
{
String str = new String(bytes,0,c);
sb.append(str);

}
fis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("初始化listener");
System.out.println(filePath) ;
System.out.println(sb.toString()+"------------------");
原创粉丝点击