1、编程实现一个时间服务器, 客户端请求服务端, 服务端返回当前时间给客户端。
2、编程实现将E:\Downloads\test.txt拷贝了D:\Downloads\下面, 目前Downloads文件夹不存在。
求各位boss解答简单Java问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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{
}catch (Exception e){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;
}log.error("异常:",e);//打印异常信息 result.put("result", "失败"); return result;
}
}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 安卓adb backup备份应用数据失败
- ¥15 eclipse运行项目时遇到的问题
- ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
- ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
- ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集
- ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
- ¥15 电力市场出清matlab yalmip kkt 双层优化问题
- ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)