命令是
hadoop fs -copyFromLocal
package com.amal.hadoop;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
/**
* @author amalgjose
*
*/
public class CopyFromLocal {
public static void main(String[] args) throws IOException {
Configuration conf =new Configuration();
conf.addResource(new Path("conf/core-site.xml"));
conf.addResource(new Path("conf/mapred-site.xml"));
conf.addResource(new Path("conf/hdfs=site.xml"));
FileSystem fs = FileSystem.get(conf);
Path sourcePath = new Path("source");
Path destPath = new Path("/user/training");
if(!(fs.exists(destPath)))
{
System.out.println("No Such destination exists :"+destPath);
return;
}
fs.copyFromLocalFile(sourcePath, destPath);
}
}
命令是
hadoop fs -copyToLocal
package com.amal.hadoop;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
/**
* @author amalgjose
*
*/
public class CopyToLocal {
public static void main(String[] args) throws IOException {
Configuration conf =new Configuration();
conf.addResource(new Path("conf/core-site.xml"));
conf.addResource(new Path("conf/mapred-site.xml"));
conf.addResource(new Path("conf/hdfs=site.xml"));
FileSystem fs = FileSystem.get(conf);
Path sourcePath = new Path("/user/training");
Path destPath = new Path("destination");
if(!(fs.exists(sourcePath)))
{
System.out.println("No Such Source exists :"+sourcePath);
return;
}
fs.copyToLocalFile(sourcePath, destPath);
}
}
你适合学Java吗?4大专业测评方法
代码逻辑 吸收能力 技术学习能力 综合素质
先测评确定适合在学习