我想用webhdfs创建一个文件到hdfs,我写了下面的函数
public ResponseEntity createFile(MultipartFile f) throws URISyntaxException {
URI uriPut = new URI(
webhdfsBaseurl+
"/gateway/default/webhdfs/v1/__MY_PATH/"+f.getName()+
"?op=CREATE" + "&overwrite=true&data=true");
ResponseEntity e = restTemplate.exchange(uriPut, HttpMethod.PUT,
new HttpEntity<Resource>(f.getResource()), Map.class);
URI location = e.getHeaders().getLocation();
System.out.println(location.toString());
URI uriPutFnal = new URI(
location+
"?op=CREATE" + "&overwrite=true&data=true");
ResponseEntity eFnal = restTemplate.exchange(uriPutFnal, HttpMethod.PUT,
new HttpEntity<Resource>(f.getResource()), Map.class);
URI uri = new URI(webhdfsBaseurl+
"/gateway/default/webhdfs/v1/_PATH_"+"?op=LISTSTATUS");
String test = restTemplate.getForObject(uri, String.class);
System.out.println(test);
return eFnal;
}
上次打印时我没有看到我的文件。。。你知道吗?
1条答案
按热度按时间iezvtpos1#