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 宇视监控服务器无法登录
- ¥15 PADS Logic 原理图
- ¥15 PADS Logic 图标
- ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
- ¥15 DruidDataSource一直closing
- ¥20 气象站点数据求取中~
- ¥15 如何获取APP内弹出的网址链接
- ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
- ¥50 STM32单片机传感器读取错误
- ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据