不多说,直接上代码。
代码
package zhouls.bigdata.myWholeHadoop.HDFS.hdfs2;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class HdfsUtil {
public static void main(String[] args) throws IOException {
// to upload a file to hdfs
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path src = new Path("hdfs://HadoopMaster:9000/jdk-7u65-linux-i586.tar.gz");
FSDataInputStream in = fs.open(src);
FileOutputStream os = new FileOutputStream("/home/hadoop/download/jdk.tgz");
IOUtils.copy(in, os);
}
}
时间: 2024-12-12 21:16:15