Neety+SpringBoot写一个基于Http协议的文件服务器

本文档介绍了如何使用Neety和SpringBoot框架创建一个基于Http协议的文件服务器。通过执行一系列命令,包括清理、打包项目,然后在目标目录下运行jar文件,可以启动并运行这个文件服务器。
摘要由CSDN通过智能技术生成

NettyApplication
package com.xh.netty;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class NettyApplication {

   public static void main(String[] args) {

      SpringApplication.run(NettyApplication.class, args);

      String[] argList =args;
      System.out.println("+++++++++++++Simple Netty HttpFileServer+++++++++++++++");
      System.out.println("+            VERSION 1.0.1                            +");
      System.out.println("+            AUTHER:XH                                +");
      System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
      if (args.length==0){
         System.out.println("Usage: java -var thisPackageName.jar [-options][args...]");
         System.out.println("Use -h for more infomation");
         System.out.println("default port is 8080 , webRoot is /root ");
      }else {
         for (int i=0;i<argList.length;i++){
            if (argList[i].equalsIgnoreCase("-h")){
               System.out.println("-p your Listern port");
               System.out.println("-f your webRoot path");
               System.out.println("Example:java -jar netty-0.0.1-SNAPSHOT.jar -p 80 -f /root");
               return;
            }else {
               if (argList[i].equalsIgnoreCase("-p")){
                  try{
                     HttpFileServer.PORT=Integer.valueOf(argList[i+1]);
                  }catch (NumberFormatException e){
                     System.out.println("wrong number for you port");
                     System.out.println("Use -h for more infomation");
                     e.printStackTrace();
                     return;
                  }
               }
               if (argList[i].equalsIgnoreCase("-f")){
                  try{
                     HttpFileServer.WEBROOT=argList[i+1];
                  }catch (Exception e){
                     System.out.println("wrong path for you webRoot");
                     System.out.println("Use -h for more infomation");
                     e.printStackTrace();
                     return;
                  }
               }
            }
         }
      }

      try {
         HttpFileServer.main();
      } catch (InterruptedException e) {
         e.printStackTrace();
      }

   }
}

HttpFileServer
package com.xh.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值