展开全部
向hadoop文件系统hdfs写入数32313133353236313431303231363533e59b9ee7ad9431333365633938据
import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.URI;import org.apache.commons.compress.utils.IOUtils;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.util.Progressable;public class FileCopyWithProgress
{ public static void main(String[] args) throws IOException
{
String localsrc = args[0];
String dst = args[1];
InputStream in = new BufferedInputStream(new FileInputStream(localsrc));
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(dst),conf);
try (OutputStream out = fs.create(new Path(dst),new Progressable(){ public void progress()
{
System.out.print(".");//用于显示文件复制进度
}
}))
{
IOUtils.copy(in, out);
}
}
}