NGC ‰2237 2022-06-20 11:00 采纳率: 50%
浏览 86
已结题

求各位boss解答简单Java问题

1、编程实现一个时间服务器, 客户端请求服务端, 服务端返回当前时间给客户端。
2、编程实现将E:\Downloads\test.txt拷贝了D:\Downloads\下面, 目前Downloads文件夹不存在。

  • 写回答

5条回答 默认 最新

  • 江湖是人情世故 2022-06-20 16:17
    关注

    package com.test.xsj.controller;

    import com.alibaba.fastjson.JSONObject;
    import lombok.extern.log4j.Log4j2;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    /**

    • @author xsj

    • @date 2022/6/20 15:43

    • /
      @RestController
      @RequestMapping("/api/time")
      @Log4j2
      public class TimeController {

      /**

      • @return 返回当前服务器时间
      • /
        @PostMapping("/getTime")
        public JSONObject getDateTime() {
        JSONObject result = new JSONObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        result.put("time", sdf.format(new Date()));
        return result;
        }

      /**

      • @return 复制xxx路径下文件到aaa路径
      • /
        @PostMapping("/cv")
        public JSONObject getCV() {
        JSONObject result = new JSONObject();
        try{
          FileInputStream in = new FileInputStream("E:/Download/test/test.txt");
          FileOutputStream out = new FileOutputStream("E:/Download/test/data/aaa.txt");
          byte[] bytearray = new byte[1024];
          do {
              in.read(bytearray, 0, 1024);
              out.write(bytearray);
          } while (in.available() > 0);
          in.close();
          out.close();
          
          result.put("result", "成功");
          return result;
        
        }catch (Exception e){
          log.error("异常:",e);//打印异常信息
          result.put("result", "失败");
          return result;
        
        }
        }

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月21日
  • 已采纳回答 6月21日
  • 创建了问题 6月20日

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址