@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg)
throws Exception {
File file = new File(msg);
if (file.exists()) {
if (!file.isFile()) {
ctx.writeAndFlush("Not a file: " + file + '\n');
return;
}
ctx.write(file + " " + file.length() + '\n');
FileInputStream fis = new FileInputStream(file);
FileRegion region = new DefaultFileRegion(fis.getChannel(), 0, file.length());
ctx.write(region);
ctx.writeAndFlush("\n");
fis.close();
} else {
ctx.writeAndFlush("File not found: " + file + '\n');
}
}
FileServer.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:distributeTemplate
作者:
评论列表
文章目录