Java 响应性<;字节[]>;通过RESTWeb服务发送字符串

Java 响应性<;字节[]>;通过RESTWeb服务发送字符串,java,arrays,string,rest,web-services,Java,Arrays,String,Rest,Web Services,我正在使用Spring和Rest web服务,但我遇到了字节数组和字符串的问题。我必须在我的ResponseEntity中发送一个字符串,在客户端我必须检索原始字符串。我无法使用ResponseEntity,因为我需要发送文件。 这是我的web服务的一部分,用于发送字符串或文件: @Override @RequestMapping(value = "/file", method = RequestMethod.GET) public ResponseEntity<byte[]&

我正在使用Spring和Rest web服务,但我遇到了
字节数组
字符串
的问题。我必须在我的ResponseEntity中发送一个字符串,在客户端我必须检索原始字符串。我无法使用
ResponseEntity
,因为我需要发送文件。 这是我的web服务的一部分,用于发送
字符串
或文件:

@Override
@RequestMapping(value = "/file", method = RequestMethod.GET) 
    public  ResponseEntity<byte[]> getAcquisition(HttpServletResponse resp,@RequestParam(value="filePath", required = true) String filePath){
        final HttpHeaders headers = new HttpHeaders();
        OutputStream outputStream = null;
        File toServeUp= null;
        try{
            toServeUp=new File(filePath);
            if (!toServeUp.exists()){
                headers.setContentType(MediaType.TEXT_PLAIN);
                LOG.error("Threw exception in MatlabClientControllerImpl::getAcquisition : File doesn't exists!!");
                String message = "ERROR: Could not retrieve file on server, check the path!";       
                return new ResponseEntity<byte[]>(message.getBytes(("UTF-8")), headers, HttpStatus.OK);
.....
但我检索了几个字符,但没有检索到通过服务器发送的字符。 我尝试过很多选择,但没有一个有效。
你知道吗?谢谢

你试过了吗?是的,我看到了。我花了大约三天的时间找到了一个可以下载和上传文件的代码,并且响应速度允许。Response是一个my类,而不是默认的“Response”,通常它类似于转换为base64的文件字节。您是否尝试从base64解码并将这些字节写入文件并检查内容。如果我使用新字符串(base64.decodeBase64(responseEntity.getBody())、Charset.forName(“UTF-8”)),它会工作。非常感谢。添加响应,以便我可以设置为true
@Override
    public Response getFile(String serverIp, String toStorePath, String filePath){
        ResponseEntity<byte[]> responseEntity = null;
        try{
            RestTemplate restTemplate = new RestTemplate();
            responseEntity  = restTemplate.getForEntity(serverIp + "ATS/client/file/?filePath={filePath}", byte[].class, filePath); 

            if (MediaType.TEXT_PLAIN.toString().equals(responseEntity.getHeaders().getContentType().toString()))
                return new Response(false, false, new String(responseEntity.getBody(),"UTF-8"), null);
....
{
  "status": false,
  "success": false,
  "result": "IlJWSlNUMUk2SUVWeWNtOXlJR2x1SUhSb1pTQndZWFJvTENCamFHVmpheUJwZENFPSI=",
  "error": null
}