public void messageReceived(ChannelHandlerContext ctx, String msg)
throws Exception {
File file = new File(msg);
if (file.exists()) {
if (!file.isFile()) {
ctx.writeAndFlush("Not a file : " + file + CR);
return;
}
ctx.write(file + " " + file.length() + CR);
RandomAccessFile randomAccessFile = new RandomAccessFile(msg, "r");
FileRegion region = new DefaultFileRegion(
randomAccessFile.getChannel(), 0, randomAccessFile.length());
ctx.write(region);
ctx.writeAndFlush(CR);
randomAccessFile.close();
} else {
ctx.writeAndFlush("File not found: " + file + CR);
}
}
FileServerHandler.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:hope-tactical-equipment
作者:
评论列表
文章目录