@Override
protected void messageReceived(ChannelHandlerContext cxt, String msg)
throws Exception {
File file = new File(msg);
if(file.exists()) {
if(!file.isFile()){
cxt.writeAndFlush("No file " + file + CR);
}
cxt.writeAndFlush("file " + file.length() + CR);
RandomAccessFile randomAccessFile = new RandomAccessFile(msg, "r");
FileRegion fileRegion = new DefaultFileRegion(randomAccessFile.getChannel(), 0, randomAccessFile.length());
cxt.write(fileRegion);
cxt.writeAndFlush(CR);
randomAccessFile.close();
}else{
cxt.writeAndFlush("File not found: " + file + CR);
}
}
FileServerHandler.java 文件源码
java
阅读 37
收藏 0
点赞 0
评论 0
项目:java_learn
作者:
评论列表
文章目录