1、编程实现一个时间服务器, 客户端请求服务端, 服务端返回当前时间给客户端。
2、编程实现将E:\Downloads\test.txt拷贝了D:\Downloads\下面, 目前Downloads文件夹不存在。
![](https://profile-avatar.csdnimg.cn/0c150bd7319a4d5e8f23635a79f23fcc_weixin_71785714.jpg!4)
求各位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 metadata提取的PDF元数据,如何转换为一个Excel
- ¥15 关于arduino编程toCharArray()函数的使用
- ¥100 vc++混合CEF采用CLR方式编译报错
- ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
- ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
- ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
- ¥50 如何openEuler 22.03上安装配置drbd
- ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
- ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
- ¥15 Windows11, backspace, enter, space键失灵