read(bytes)

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()+"------------------");

你可能感兴趣的:(bytes)