expected: file:///
时间: 2023-11-17 10:04:42 浏览: 61
这个错误提示是因为你的HDFS系统无法识别HDFS文件,而期望在本地路径上找到文件。解决这个问题的方法有两种:
1. 显式地指定文件路径为本地路径,例如使用"file:///"前缀。
2. 在代码中添加其他配置文件,例如使用conf.addResource()方法来添加core-site.xml文件。
参考代码如下:
1. 显式指定文件路径为本地路径:
Configuration conf = new Configuration();
try {
FileSystem fs = FileSystem.get(conf);
Path f = new Path("file:///dfs_operator.txt");
FSDataOutputStream os = fs.create(f, true);
int i = 0;
for (i = 0; i < 10; ++i)
os.writeChars("test");
os.close();
} catch (IOException e) {
e.printStackTrace();
}
2. 添加其他配置文件:
Configuration conf = new Configuration();
conf.addResource(new Path("/home/hadoop/conf/core-site.xml"));
try {
FileSystem fs = FileSystem.get(conf);
Path f = new Path("hdfs:///dfs_operator.txt");
FSDataOutputStream os = fs.create(f, true);
int i = 0;
for (i = 0; i < 10; ++i)
os.writeChars("test");
os.close();
} catch (IOException e) {
e.printStackTrace();
}