package com.lxw; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.util.Progressable; public class URLCat { public static void main(String[] args) throws Exception { String src = "D:/ip1.txt"; String dst = "hdfs://localhost:3333/lxw/input/2.txt"; InputStream in = new BufferedInputStream(new FileInputStream(src)); Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(URI.create(dst), conf); OutputStream os = fs.create(new Path(dst),new Progressable(){ public void progress() { System.out.print("."); } }); IOUtils.copyBytes(in, os, 4096, true); } }