hdfs深入:08、hdfs的JavaAPI以及如何解决winutils的问题

mac2022-06-30  70

/** * 通过url注册的方式访问hdfs,了解,不会用到 * @throws Exception */ 以下为详细代码://1.注册hdfs的url,让java代码能识别hdfs的url形式URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());InputStream in = null;FileOutputStream out = null;//定义文件访问的url地址String url = "hdfs://node01:8020/test/input/install.log";//打开文件输入流in = new URL(url).openStream();out = new FileOutputStream(new File("D:\\installOut.txt"));IOUtils.copy(in,out);IOUtils.closeQuietly(in);IOUtils.closeQuietly(out);

 

执行hdfs文件操作的时候抛异常 winutils:

19/05/30 22:24:34 ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary pathjava.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.

解决步骤:

第一步:把 F:\传智播客大数据离线阶段课程资料\3、大数据离线第三天\解决winutils的问题\hadoop-2.6.0-cdh5.14.0 这个安装包拷贝到一个没有中文没有空格的路径下面去(D:\Develop\hadoop-2.6.0-cdh5.14.0);

第二步:在windows上面配置hadoop的环境变量:

1.添加HADOOP_HOME=D:\Develop\hadoop-2.6.0-cdh5.14.0

2.在PATH中添加:%HADOOP_HOME%\bin;%HADOOP_HOME%\sbin;

第三步:D:\Develop\hadoop-2.6.0-cdh5.14.0\lib\native\hadoop.dll  文件放到本地系统盘的 C:\Windows\System32 目录下;

第四步:关闭windows重启。

 

转载于:https://www.cnblogs.com/mediocreWorld/p/10947141.html

最新回复(0)