我使用以下程序重命名目录,但出现异常,这似乎仅是假设我正在使用本地文件系统.实际上,在我的core-site.xml中,我已经将fs.default.name设置为hdfs,而不是本地文件系统.
因此,我想知道配置文件的加载顺序,以及为什么它认为我正在使用本地文件系统.如何解决?谢谢
`
fs.default.name
hdfs://xiliu:54310
true`
hadoop.tmp.dir
/data1/hadoop/hdfs/tmp
true
public class FSUtil extends Configured
{
private static Configuration conf;
static
{
conf = new Configuration( );
}
public static void rename( Path srcPath, Path tgtPath)
throws IOException
{
FileSystem fs = FileSystem.get( conf);
fs.rename( srcPath, tgtPath);
}
public static void main(String[]args){
try {
FSUtil.rename(new Path("hdfs://xiliu:54310/user/warehouse/test"), new Path("hdfs://xiliu:54310/user/warehouse/testtmp"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://xiliu:54310/user/warehouse/test, expected: file:///
at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:354)
at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:54)
at org.apache.hadoop.fs.RawLocalFileSystem.getFileStatus(RawLocalFileSystem.java:367)
at org.apache.hadoop.fs.FileSystem.isDirectory(FileSystem.java:702)
at org.apache.hadoop.fs.ChecksumFileSystem.rename(ChecksumFileSystem.java:402)
at com.business.cloudbase.hadoop.fs.FSUtil.rename(FSUtil.java:251)
at com.business.cloudbase.hadoop.fs.FSUtil.main(FSUtil.java:602)
解决方法:
看起来配置文件不在类路径中,并且fs.default.name参数默认为file:///.
两种选择
>将配置文件放在类路径中,以便代码选择它.
>使用Configuration.set()在代码中设置所需的参数.
标签:mapreduce,hadoop,java
来源: https://codeday.me/bug/20191202/2086261.html